0

I'm looking for a simple utility that I could configure to a hotkey which would allow me to toggle ON/OFF my Mac's Wi-Fi.

1

4 Answers 4

3

You could assign a shortcut to a script like this using an app like FastScripts or Alfred:

#!/bin/bash

device="$(networksetup -listallhardwareports |
grep -E '(Wi-Fi|AirPort)' -A 1 | grep -o "en.")"
[[ "$(networksetup -getairportpower $device)" == *On ]] && val=off || val=on
networksetup -setairportpower $device $val

If you use Alfred and have the Powerpack, there's an extension called Toggle wifi on/off that basically just runs a shell script like the one above.

1

We built Airtoggle exactly for this. It's great for people who don't want to use scripts etc. http://www.axoniclabs.com/Airtoggle/

1

Something like this worked for me.

So I made the following alias commands for use within Terminal on the command line interface.

alias adhoc='networksetup -setairportnetwork en1 <adhoc SSID>'
alias wifi='networksetup -setairportnetwork en1 <my wifi SSID> <WPA2 password>'
1
  • 1
    I used a similar approach to cycle the Wi-Fi. Put it in an Automator workflow > Run shell script. Save as Application or Service (to use a hotkey): networksetup -setairportpower en0 off; networksetup -setairportpower en0 on
    – brandonjp
    Sep 23, 2012 at 17:02
0

Although there seems to be no reliable way of turning AirPort on or off directly via the shell, it is possible to get around that by manipulating OS X's Locations with the scselect command.

First, create a new location called AirPort-Off in the Network preferences pane. With this new location selected, select Network Port Configurations under the Show pop-up menu, and deselect AirPort. Then select your previous location, which for most people would probably be Automatic.

Now, you can turn AirPort off by running scselect AirPort-Off and back on by running the last command, replacing AirPort-Off with the name of your normal location name. To assign a hot key to the command using a utility like Butler, create a simple AppleScript containing this one line:

do shell script "/usr/sbin/scselect AirPort-Off"

Then have Butler (or your app of choice) run that APpleScript. (With Butler, running a shell script containing only the bare command doesn't seem to work.)

1
  • 1
    networksetup -setairportpower en0 off and networksetup -setairportpower en0 on works. Dec 11, 2012 at 13:40

You must log in to answer this question.

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