if you find it intresting a ⭐️ on GitHub would mean a lot!
A macOS utility that monitors Wi-Fi network changes and executes user-defined scripts when connecting to or disconnecting from networks.
- Monitors Wi-Fi SSID changes in real-time
- Detects connections, disconnections, and network switches
- Executes custom scripts based on powerful condition matching:
- When connecting to any network
- When disconnecting completely from Wi-Fi
- When switching from one network to another
- When connecting to specific networks using pattern matching
- When transitioning from one specific network to another
- Provides context-aware environment variables to scripts
- Simple configuration with flexible condition syntax
- Advanced condition combinations for complex triggers
brew install ramanaraj7/tap/wifiwatcherStart the service using Homebrew:
brew services start wifiwatcherClone the repository:
git clone https://github.com/ramanaraj7/wifiwatcher.git
cd wifiwatcherCompile the application:
clang -framework Foundation -framework CoreWLAN -fobjc-arc -o wifiwatcher wifiwatcher.mCopy the binary to a location in your PATH:
sudo cp wifiwatcher /usr/local/bin/Create a LaunchAgent to run at login:
mkdir -p ~/Library/LaunchAgents
cp homebrew.mxcl.wifiwatcher.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.wifiwatcher.plistRun the setup to create your configuration file:
wifiwatcher --setupRun the setup command to create your configuration file:
wifiwatcher --setupThis creates:
~/.wifiwatcherconfiguration file with example configurations
Edit ~/.wifiwatcher to define your triggers and scripts:
# Format: /path/to/script {condition1} {condition2} ...
# Basic conditions:
# {on:connect} - Run when connecting to any network
# {on:disconnect} - Run when disconnecting from Wi-Fi completely
# {on:change} - Run when switching from one network to another
# SSID matching conditions:
# {wifi:SSID} - Run when connecting to exact SSID
# {wificontain:str} - Run when SSID contains string
# {wifinotcontain:str} - Run when SSID does not contain string
# {wifistart:str} - Run when SSID starts with string
# {wifiend:str} - Run when SSID ends with string
# Transition conditions:
# {from:SSID} - Run when disconnecting/changing from specific SSID
# {to:SSID} - Run when connecting to specific SSID
# Examples:
echo "Connected to $WIFI_SSID" {on:connect} # Direct command
~/bin/vpn-connect.sh {wifi:CompanyWiFi} # Script for specific network
osascript -e 'display notification "Public Wi-Fi"' {wificontain:Public} # Run AppleScript
/usr/local/bin/notify.sh {on:disconnect} # Run on disconnection only
~/monitors.sh {on:disconnect} {from:KGP} # Run when disconnected from KGP
~/monitorf.sh {from:wificontain:KGP} # Run when switching from KGP network
~/monitorf.sh {on:change} {from:KGP} {to:KGP-5G} # Run when switching between specific networks
WiFiWatcher supports advanced condition combinations:
# Combined filters:
{from:wificontain:str} - From network containing string
{to:wifiend:str} - To network ending with string
# Standalone transitions:
{from:X} - Any network change from X
{from:X} {to:Y} - Switching directly from X to Y
# Event-specific transitions:
{on:change} {from:X} {to:Y} - Switch from network X to Y
{on:disconnect} {from:X} - Disconnect or switch from network X
{on:connect} {from:X} - Connect after previously being on network X
Start the service using Homebrew:
brew services start wifiwatcherbrew services start wifiwatcher # Start the service
brew services stop wifiwatcher # Stop the service
brew services restart wifiwatcher # Restart the service
brew services info wifiwatcher # Check service statusFor manual installation, use launchctl:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.wifiwatcher.plist # Start
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.wifiwatcher.plist # Stopwifiwatcher --help # Show help message
wifiwatcher --version # Show version information
wifiwatcher --setup # Create configuration file
wifiwatcher --monitor # Can be used to test out manualy and debugScripts receive these environment variables which can be used inside ~/.wifiwatcher:
WIFI_SSID- Current SSID or '(none)' if disconnectedWIFI_CONNECTED- YES or NOWIFI_RSSI- Signal strength in dBmWIFI_PREVIOUS_SSID- Previous SSID (when available)WIFI_TIMESTAMP- Current timestamp (UTC)WIFI_TRIGGER_REASON- Describes why the script was executed
{on:change}triggers when switching between networks (directly or after disconnection)- Direct WiFi conditions (like
{wifi:SSID}) trigger on initial connection and reconnections - Combined conditions (like
{on:connect} {from:X}) require all parts to match - Scripts can be direct shell commands or paths to executable files or other scripts
MIT License