Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
How can I reset network (Airport) connections from the command line?

How can I set up a keyboard shortcut to toggle the Airport (on/off) on OS X?

enter image description here

share|improve this question

marked as duplicate by Daniel Beck, slhck, Simon Sheehan, Sathya Nov 11 '11 at 9:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 4 down vote accepted

Based on a similar question How can I reset network (Airport) connections from the command line?

Create two applescript files:

do shell script "/usr/sbin/networksetup -setairportpower en1 on"
do shell script "/usr/sbin/networksetup -setairportpower en1 off"

Then use fastscripts to assign keyboard shortcuts to them.

share|improve this answer
On some Macs the ethernet device number is en0 or en2. – user495470 Nov 27 '11 at 21:23

I found this:

Toggle AirPort on and off using keyboard shortcuts
Oct 17, '08 07:30:03AM • Contributed by: Anonymous

This is the simplest way I've found to toggle the AirPort card on and off without using third party applications or too many buttons. Hopefully others will appreciate this function as I do. Note: This function is tailored to a MacBook, as the F5 and F6 keys have no predetermined function on these machines. Other machines may need the shortcut keys to be edited.

1- Create two keyboard shortcuts. Go to the Apple menu » System Preferences » Keyboard & Mouse » Keyboard Shortcuts tab. Click the plus sign at the bottom of the window, and select All Applications from the pop-up menu in the next dialog. In the Menu Title box, type Turn AirPort On with that exact case and spelling. Set the Keyboard Shortcut to F5, then click Add. Click the plus sign again, leave the pop-up menu set to All Applications, and in the Menu Title box, type Turn AirPort Off with the shortcut key also set to F5 -- only one of these functions will be displayed at a time.

2 - In the Keyboard Navigation section of the same window, change the 'Move focus to status menus in the menu bar' to F6 (and check the box to enable this shortcut, if it's not yet enabled).

3 - Make sure the AirPort icon is in your menu bar. Then hold down the Command key and drag the AirPort Menu bar icon as far to the left as possible. This insures that it is the first to be selected when you move focus to the menu bar.

4 - Finally, restart your system. After your Mac reboots, press F6 to move focus to the menu bar, and F5 to toggle AirPort on or off, depending on its current state.

Aside from the problem with dragging to the left-most position (as other Mac "shortcuts" require that same position), this should work fine.

share|improve this answer

device="$(networksetup -listallhardwareports |
grep -E '(AirPort|Wi-Fi)' -A 1 | grep -o "en.")"
[[ "$(networksetup -getairportpower $device)" == *On ]] && val=off || val=on
networksetup -setairportpower $device $val
share|improve this answer
great, thanks! I think this is better. BTW some reason mine was called AirPort and not Wifi. Strage. – cwd Nov 27 '11 at 19:44
@cwd Apple started calling AirPort Wi-Fi everywhere in Lion. Grepping for either should make the script work on both 10.6 and 10.7. – user495470 Nov 27 '11 at 21:19
Cool - good to know this. – cwd Nov 28 '11 at 0:54
This is beautiful. Wish I had two upvotes for this. – Ashutosh Jindal Aug 27 '12 at 8:08

Not the answer you're looking for? Browse other questions tagged .