Turning your Airport Card on and off
This is a simple tip I stumbled across a month or so ago. There were some bugs in Leopard wireless that wouldn’t let me connect to the encrypted wireless network at work after a machine was restarted. I found that turning the airport card on and off let me connect again. I hated having to remember this every time I restarted so I dug around and found that the command line tool networksetup can do it for me. Great!
This tool exists on Tiger machines in the Apple Remote Desktop client bundle. The path to it is:
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup
Fortunately they very kindly included it in the build for Leopard. The path in Leopard is:
/usr/sbin/networksetup
So, in Leopard, to turn the Airport card off enter the following in Terminal:
/usr/sbin/networksetup -setairportpower off
To turn the card back on change “off” to “on”. If you’re running Tiger make sure to change the path so it points to the app correctly.
Put both of these commands in an AppleScript, save it as an application and add it to your Login items. Then, when the machine is rebooted the card gets turned off and then on and in my case makes my wireless connection.
Snow Leopard changes
In Snow Leopard the command remains, however now you need to run it as sudo
. You also need to include the actual network device name AirPort is running on. You can get that by running the following command:
/usr/sbin/networksetup -listallhardwareports
You’ll see Airport listed and below it the device. If the machine does not have two Ethernet ports AirPort is commonly listed as “en1”
After you have that you include it in your command:
sudo /usr/sbin/networksetup -setairportpower en1 on
I’ve included these changes and a routine that will find the airport device in the Snow Leopard version of the script.
Click here to download a copy of the script for Tiger/Leopard:
Airport off and on
Click here to download a copy of the script for Snow Leopard:
Snow Leopard Airport off and on
networksetup is a great tool for administrators and even just people who want a little more control over their machines.
webmaster :: Jan.07.2008 :: Applescript, Management, Scripts, System, Terminal :: 23 Comments »
23 Responses to “Turning your Airport Card on and off”
Thanks .. I have been looking for scrips to set proxy on and off for my corporate environment. I was able to take this and modify this to do it 🙂
Thanks, also.
But what command would one use to first establish whether AirPort is on or off, prior to running the script?
You would run
/usr/sbin/networksetup -getairportpower
That will return either an “on” or “off” message.hello
i tried this with leopard and what just run for me great what i downloaded from your script
but i have one problem
i can’t edit with my script editor and texteditor no changes
it’s would be great when somebody can for me compiled the script as programm so that i can but in autostart
looking forward for your help
with an another computer i’m was able to compile via script programm
now i but it in autostart and had several test’s
i have still the problem no connections sometimes i think i need a delay or wait in the script after all the system is finished start and than again run
when i start it manualy is everithing ok
do you now what i have to put in my script for a delay? or what syntax i have to user
Try adding this to the very first line of the script
delay 5
with 5 being the number of seconds you want the script to wait before running.
You, Sir, and the Man. Applescript perfection. Tusen takk!
Whoops. Make that “are” the Man…..
thanks for your help
no longer works in OS X 10.6. I get “cp: /Library/Preferences/SystemConfiguration/preferences.plist.old: Permission denied” error when run in applescript editor. Any ideas?
@SYDEcg – check the post above for changes for Snow Leopard. Thanks for letting me know.
Thanks and thanks — the change in parameters for Snow Leopard broke my script, but your tip set me (and my Airport) up!
I am running a MacBook Pro, 2.2 Ghz Intel core 2 duo, 10.5.8
Can not get my airport card to turn on. Tried
/usr/sbin/networksetup -setairportpower on
Got request denied
Where to next? Thank you for any help you can provide.
Regards, Roger
You have to run that command as root. Make sure you put “sudo” in front of it.
sudo /usr/bin/networksetup -setairportpower on
Hi,
i have i BIG problem: when the iHac goes to sleep (EP45-DS4), the airport card is gone at wake-up. It is deactivated, the triangle in menubar is empty and there is no way to turn it back on without rebooting.
i’m running Snow leopard
tried : sudo /usr/bin/networksetup -setairportpower on but it still stays off.
looks like the pci-e port wouldn’t wake up again..
I would greatly appreciate any help on that
– tried to give fixed ip : no way
– tried to put connexion on top : no way
– tried turning true poweroff to false in kext : no way
… 🙁
Much thanks to the creator of this script saved me alot of time!
This is gold. Thanks so much!
Thanks for the post. very helpful.
[…] AirPort ??????????????????? Automator […]
Thanks, very helpful.
But I could execute /usr/sbin/networksetup without sudo. Is it because my account is system admin?
Sounded good. I have a 500MHz Ti powerbook with a PCI WiFi card and if it is removed (turn off airport and the card power first) and then reinserted, airport will not restart (button is grayed out). The computer see the card as the menu bar icon reappears, but Airport thinks no airport card exists. This didn’t help.
I thought I’d add here that for the SL script to work in Lion change line 13 “AirPort” to “Wi-Fi” , as airport has been taken out of MacOs terminology.
It is this line for clarity: if text item x of the_ports contains “Wi-Fi” then
To webmaster; thank you very much! I was looking for a script to just turn wi-fi off and yours did it with just a couple of modifications.
Best regards
jz
In your article, you explain that the Snow Leopard version needs to run as sudo. But in your “Snow Leopard Airport off and on” script, why don’t you have the shell script command’s content begin with sudo? Is sudo *assumed* when a “do shell script” line ends with: user name “yourUserShortName” password “yourUserPassword” with administrator privileges? Or did you just inadvertently leave the sudo out?