Disable AirPort when Ethernet cable is connected

From MacOSXHints…

At my office, I needed to find a way to turn of the wireless network when someone plugged in their network cable. I also did not want them to be able to turn the wireless network back on until the network cable was unplugged. I came up with the fallowing solution.

I created a launchDaemon called com.companyname.ethernetmonitor, and saved it in /System/Library/LaunchDaemons:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>com.companyname.ethernetmonitor</string>
  <key>ProgramArguments</key>
  <array>
    <string>/Library/Scripts/CompanyName/turnOffAirport.sh</string>
  </array>
  <key>WatchPaths</key>
  <array>
    <string>/Library/Preferences/SystemConfiguration</string>
  </array>
</dict>
</plist>

This will watch the System Configurations folder for changes. This folder changes when you plug in a network cable, turn on AirPort, etc. When it changes, a script called turnOffAirport.sh, stored in /Library/Scripts, is run to see if the Ethernet connection has a company IP address:
#!/bin/sh
if ifconfig en0 | grep 155.144;
then /usr/sbin/networksetup -setairportpower off
else
exit 0
fi
This helps keep the user from grabbing two IPs (our wireless and wired network use the same set of IPs), and also helps prevent a few other odd issues when a user is connected to both wireless and Ethernet networks.


I suspect that this can easily be made to work both ways… At the present time, it appears to turn off the wireless, but not automatically turn it back on.

That could be by design. After all, the laptop will be consuming more power with wireless turned on…. But, I believe by changing the exit 0, to /usr/sbin/networksetup -setairportpower on would be enough to change the behavior…