Wednesday, March 26, 2008

Toggle Airport Power On/Off with AppleScript

If you want to quickly step down your MacBook's power consumption, or you've accidentally hit "send message" for an incomplete or wrongly destined email etc., you'd need to immediately terminate your Internet connection. The best way I've found for doing that is by toggling your airport's power directly.

First, if you don't have MacPorts already installed, visit The MacPorts Project and follow the installation instructions there.

Then, use the terminal command "sudo port install airport".

Finally, save the script below into a file that you can run from the dock or tie it to a handy iKey shortcut.

-- make sure to first use macports to intall the airport port using the Terminal command "sudo port install airport"
-- the airport -p command returns "Power is on/off." but off is considered an error

do shell script "/opt/local/bin/airport -p"
do shell script "/opt/local/bin/airport -P 0"
on error
do shell script "/opt/local/bin/airport -P 1"
end try