This is a bash script that will automatically turn your wifi off if you connect your computer to an ethernet connection and turn wifi back on when you unplug your ethernet cable/adapter. If you decide to turn wifi on for whatever reason, it will remember that choice. This was improvised from this mac hint to work with Yosemite, and without hard-coding the adapter names. It's supposed to support growl, but I didn't check that part. I did, however, add OSX notification center support. Feel free to fork and fix any issues you encounter.
Most the credit for these changes go to Dave Holland.
- Mac OSX 10+
- Administrator privileges
- Copy
toggleAirport.sh
to/Library/Scripts/
- Run
chmod 755 /Library/Scripts/toggleAirport.sh
- Copy
com.mine.toggleairport.plist
to/Library/LaunchAgents/
- Run
chmod 600 /Library/LaunchAgents/com.mine.toggleairport.plist
- Run
sudo launchctl load /Library/LaunchAgents/com.mine.toggleairport.plist
to start the watcher
- Run
sudo launchctl unload /Library/LaunchAgents/com.mine.toggleairport.plist
to stop the watcher - Delete
/Library/Scripts/toggleAirport.sh
- Delete
/Library/LaunchAgents/com.mine.toggleairport.plist
- Delete
/private/var/tmp/prev_eth_on
- Delete
/private/var/tmp/prev_air_on
To debug, just run: sudo /Library/Scripts/toggleAirport.sh
and add echo's wherever you'd like
Thanks to this thread for the ideas. I've just created a new version of this in case anyone is interested. Tested on macOS 14.3.
Download and save in your path as
wifi-toggle.sh
(any name will work).You need to open the script and change the
ETHERNET_REGEX
variable to match the name of your ethernet device. You can find the name of your device by runningnetworksetup -listnetworkserviceorder
. Your ethernet device name is the text after number in parenthesis (eg.(2) CalDigit TS3
).Run
wifi-toggle.sh on
and it will install a launchd service in~/Library/LaunchAgents
.Now ...
If you want to stop the automatic toggle, run
wifi-toggle.sh off
.