Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Toggle Airport On and Off Network
The hint 'Control Airport Without Menu Bar' in the June issue of Macworld (also see this article) was very informative and useful. I devised a simple script based on the article hint that toggles airport on and off.

Here is the script. Copy and Paste it into AppleScript Editor and save it as an Application.
-- Toggle Airport Power On and Off
if (offset of "On" in (do shell script "networksetup -getairportpower en1")) > 0 then
	do shell script "networksetup -setairportpower en1 off"
	do shell script "networksetup -setairportpower en1 on"
end if

[crarko adds: I tested this, and it works as described. It follows precisely the method described in the linked Macworld article, in case you hadn't seen that.]
  • Currently 3.43 / 5
  You rated: 2 / 5 (7 votes cast)

Toggle Airport On and Off | 8 comments | Create New Account
Click here to return to the 'Toggle Airport On and Off' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Toggle Airport On and Off
Authored by: Spazed on May 24, '11 09:35:39AM

sudo ifconfig en1 down

sudo ifconfig en1 up

Will also turn the airport on and off, as long as 'en1' is the correct interface.

[ Reply to This | # ]
Toggle Airport On and Off
Authored by: merlyn on Jun 03, '11 05:28:46PM

Yeah, I was wondering the same thing. People seem to want to solve things the hard way here in the past few days. :)

[ Reply to This | # ]
Toggle Airport On and Off
Authored by: Michael_S on May 24, '11 05:48:23PM

What problem, exactly, does this hint solve?

If you want to click, have AirPort show in the menu bar and click there. If you want a command line tool, use networksetup(8). No need to wrap that in AppleScript and then in an app, which you need to locate to click on, and which you need to install again on other Macs you'd use.

[ Reply to This | # ]
Toggle Airport On and Off
Authored by: CHM on May 24, '11 08:24:21PM

The purpose is to allow you to toggle Airport power with keyboard shortcuts. The Macworld article linked to discusses this, but provides two separate scripts for turning the Airport on or off. The script in this hint toggles the state with one script.

[ Reply to This | # ]
Toggle Airport On and Off
Authored by: Michael_S on May 24, '11 09:10:57PM
Still not getting it - where would one need to do this so often that one needs a shortcut?

Every Mac comes with a mouse or trackpad, and to switch Airport I need basically one gesture: mouse-down on the Airport icon in the Menu Bar, drag down, mouse-up. No need to write and install a script, maintain Butler or some such, sync its config, and the script itself.

I use several Macs at home and work, occasionally in different user accounts, and experience has taught me that it's more efficient in the long run to learn what each system brings with it than to try futzing with custom UI add-ons. (I also drastically cut back reliance on shell aliases and such for exactly the same reason.)

If you're still bent on using the keyboard: Ctrl-F8 gets you to the status section of the Menu Bar, and arrow keys to the Turn Airport On or Off menu entry. Press Enter to toggle.

Alternatively: Leverage multiple Network Locations, and toggle them via the Apple menu -- Ctrl-F2 etc. This of course needs setup but also solves yet a different problem, and quite cleanly.

[ Reply to This | # ]

Toggle Airport On and Off
Authored by: CHM on May 25, '11 06:23:51AM

Personally, my MacBook's Airport hangs a lot. It's old but I'm not ready to replace it yet. Turning Airport off then on again fixes the problem for a while. Rather than mousing up to the Airport menu bar icon, clicking, mousing down to "Turn Airport Off", clicking, then mouing back up, clicking the Airport icon again, mousing down to Turn Airport On, and clicking one last time, it is way faster to do a keyboard shortcut twice. It's also faster than all the keystrokes needed to do the same via the ctrl-F8 option.
In my case, I just got rid of the part of the script that makes it toggle power and just have the script turn it off and back on again. All by pressing 3 keys, just once.

[ Reply to This | # ]
Toggle Airport On and Off
Authored by: Hmbucker on Dec 06, '11 06:16:23AM

The reason I want to be able to toggle it using short cuts is because I am using a huge extended desktop and tracking to the icon causes RSI in my case. I am on 2 networks at work, one which allows pop mail accounts and the other one doesn't. If I wan't to check my email accounts, I need to switch networks.

[ Reply to This | # ]
Toggle Airport On and Off
Authored by: StrawHousePig on May 25, '11 07:24:11AM

To answer your question, for me the AirPort menuextra does nothing. I cannot even turn AirPort off in System Preferences - Network. This hint, while not a 'fix' for the problem is a work around that does something I can use.

To ask a question of my own, since when do hints need to be fixes?

[ Reply to This | # ]