Posts RSS Comments RSS 37 Posts and 56 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.

Add a Link:
  • Twitter
  • Facebook
  • Digg
  • Reddit
  • del.icio.us
  • Google Bookmarks
  • LinkedIn
  • StumbleUpon
  • Technorati
  • email

14 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

Trackback this post | Feed on Comments to this post

Leave a Reply