Posts RSS Comments RSS 48 Posts and 155 Comments till now

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.

23 Responses to “Turning your Airport Card on and off”

  1. on 09 Apr 2009 at 7:12 pmManu

    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 🙂

  2. on 25 Apr 2009 at 4:33 pmCD

    Thanks, also.

    But what command would one use to first establish whether AirPort is on or off, prior to running the script?

  3. on 25 Apr 2009 at 4:48 pmwebmaster

    You would run /usr/sbin/networksetup -getairportpower That will return either an “on” or “off” message.

  4. on 25 Apr 2009 at 5:18 pmtomy99

    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

  5. on 26 Apr 2009 at 5:43 amtomy99

    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

  6. on 26 Apr 2009 at 8:06 amwebmaster

    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.

  7. on 27 Apr 2009 at 1:43 pmCD

    You, Sir, and the Man. Applescript perfection. Tusen takk!

  8. on 27 Apr 2009 at 1:43 pmCD

    Whoops. Make that “are” the Man…..

  9. on 28 Apr 2009 at 11:07 amtomy99

    thanks for your help

  10. on 11 Sep 2009 at 10:39 amSYDEcg

    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?

  11. on 11 Sep 2009 at 11:36 amwebmaster

    @SYDEcg – check the post above for changes for Snow Leopard. Thanks for letting me know.

  12. on 29 Oct 2009 at 3:52 pmJoshua

    Thanks and thanks — the change in parameters for Snow Leopard broke my script, but your tip set me (and my Airport) up!

  13. on 17 Apr 2010 at 4:47 pmRoger Lohn

    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

  14. on 17 Apr 2010 at 4:49 pmwebmaster

    You have to run that command as root. Make sure you put “sudo” in front of it.

    sudo /usr/bin/networksetup -setairportpower on

  15. on 14 Sep 2010 at 5:25 pmcybercap

    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
    … 🙁

  16. on 19 Jan 2011 at 5:32 amCD

    Much thanks to the creator of this script saved me alot of time!

  17. on 31 Jan 2011 at 1:14 amSean

    This is gold. Thanks so much!

  18. on 13 Apr 2011 at 11:39 amSurendra

    Thanks for the post. very helpful.

  19. […] AirPort ??????????????????? Automator […]

  20. on 11 May 2011 at 8:22 amYu-Cheng Chuang

    Thanks, very helpful.

    But I could execute /usr/sbin/networksetup without sudo. Is it because my account is system admin?

  21. on 13 Jun 2011 at 10:30 amPaul

    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.

  22. on 20 Feb 2012 at 10:45 pmJesse

    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

  23. on 23 Mar 2014 at 8:27 pmSchmye Bubbula

    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?