« It's "kick the IT guy" season again | Main | Yet another nail in the "Bloggers are Real Journalists" coffin »

A quick "Airplane Mode" script

For those of you wanting a (close to) one step way to toggle airport and bluetooth on and off ala "Airplane mode" on a cell phone:

property bluetoothDaemonPath : "/usr/sbin/blued"
property bounceBlueD : "/usr/bin/killall -SIGHUP blued"
property bluetoothOn : "/usr/bin/defaults write com.apple.Bluetooth \"ControllerPowerState\" 1"
property bluetoothOff : "/usr/bin/defaults write com.apple.Bluetooth \"ControllerPowerState\" 0"
property airportOn : "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setairportpower on"
property airportOff : "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setairportpower off"

try
set theAirplaneModeRecord to display dialog "Click the appropriate button to enable or disable Airplane Mode on your Mac" buttons {"Cancel", "Airplane Mode On", "Airplane Mode Off"} default button "Cancel" with icon caution giving up after 60
set theAirplaneModeButton to button returned of theAirplaneModeRecord

if theAirplaneModeButton is "Cancel" or "" then
quit
else if theAirplaneModeButton is "Airplane Mode On" then
do shell script airportOff with administrator privileges
do shell script bluetoothOff
do shell script bounceBlueD with administrator privileges
else if theAirplaneModeButton is "Airplane Mode Off" then
do shell script airportOn with administrator privileges
do shell script bluetoothOn
do shell script bounceBlueD with administrator privileges
else
quit
end if
end try

Technorati Tags: ,

Posted by John C. Welch at 11:20 | Permalink


Comments

Nice! That was quick. :-) Thanks!

David Weiss

Posted by: David Weiss | June 26, 2007 12:34 PM

Actually, I wrote it about a year and a half ago ;-)

Posted by: John C. Welch | June 26, 2007 10:45 PM

Very useful--given I'm on flight 74 for 2007 tomorrow, this combined with my magsafe adapter will make it all that much smoother :)

Posted by: Andy | June 27, 2007 5:49 PM

Couldn't you do this with Locations?

Posted by: grover | June 28, 2007 12:42 PM

You could grover, but creating locations with no wireless connections is not always what you want to do. Both techniques accomplish the same thing, just from different angles.

Posted by: John C. Welch | June 28, 2007 2:30 PM

So I grabbed this script around the time you posted it, but haven't done much travelling since then. Today, of course I am on the proverbial road visiting family for turkey and I tried out the script only to find that it is broken on Leopard. Here's an updated version for Leopard (only):

property bluetoothDaemonPath : "/usr/sbin/blued"
property bounceBlueD : "/usr/bin/killall -SIGHUP blued"
property bluetoothOn : "/usr/bin/defaults write /Library/Preferences/com.apple.Bluetooth \"ControllerPowerState\" 1"
property bluetoothOff : "/usr/bin/defaults write /Library/Preferences/com.apple.Bluetooth \"ControllerPowerState\" 0"
property airportOn : "/usr/sbin/networksetup -setairportpower on"
property airportOff : "/usr/sbin/networksetup -setairportpower off"

try
set theAirplaneModeRecord to display dialog "Click the appropriate button to enable or disable Airplane Mode on your Mac" buttons {"Cancel", "Airplane Mode On", "Airplane Mode Off"} default button "Cancel" with icon caution giving up after 60
set theAirplaneModeButton to button returned of theAirplaneModeRecord

if theAirplaneModeButton is "Cancel" or "" then
quit
else if theAirplaneModeButton is "Airplane Mode On" then
do shell script airportOff with administrator privileges
do shell script bluetoothOff
do shell script bounceBlueD with administrator privileges
else if theAirplaneModeButton is "Airplane Mode Off" then
do shell script airportOn with administrator privileges
do shell script bluetoothOn
do shell script bounceBlueD with administrator privileges
else
quit
end if
end try

I'd like to thank Nigel Kersten and whoever writes The Adventures of Systems Boy for their recent posts which helped me to update the script, and of course, John for posting it in the first place.

Posted by: C.J. Zinngrabe | November 22, 2007 5:54 PM

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?


digital.forest Where Internet solutions grow

 
Family
The Artwork of Melissa Findley
Diane Francis @ the National Post Eric Francis @ the Calgary Sun
Apple Amazon Links
Apple Mac OS X Server 10.5 [Unlimited]

Apple Mac OS X Server 10.5 [10-Client]

Apple Mac OS X 10.5 Leopard

Apple Mac OS X 10.5 Leopard [5-User Family Pack]

Amazon Book Links
Legacy of Ashes: The History of the CIA

The Donnas: Bitchin'

Wizards at War (The Young Wizards, Book 8)

The Demon's Sermon on the Martial Arts

The Collected Stories of Arthur C. Clarke

JavaScript and Ajax for the Web, Sixth Edition

Awakening Warrior: Revolution in the Ethics of Warfare

FOB Links

Mac Web Writers

Techie Links

Review Victims