You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to turn Wi-Fi on / off with a shortcut

I would like to be able to turn Wi-Fi on and off with a shortcut (Control-W or something like that).

I have tried to enable this on the Shortcuts part of the Keyboard Preferences, but with no luck.

App Shortcuts / All Applications / Turn Wi-Fi On - does not work.

Is there a way to do this?

iMac, OS X Mavericks (10.9)

Posted on Jul 19, 2014 12:17 AM

Reply
Question marked as Top-ranking reply

Posted on Jun 25, 2015 2:19 AM

Some Macs have the WiFi port is not 'en1' as in the Barney-15E's script (ex: MacBook Pro Retina 15 with Yosemite).

So, the script will work for switch WiFi to ON only.

I think it's regular for new Apple laptops without Ethernet RJ45 port.


To solve the problem it should be define which en* port is WiFi in the system.


I used the Terminal command:

$ networksetup -listallhardwareports


and find my WiFi as 'en0' :


$ networksetup -listallhardwareports


Hardware Port: Wi-Fi

Device: en0

Ethernet Address: 12:00:7h:cb:c7:11


So the Barney-15E's beautiful script changed to:


if [[ `networksetup -getairportpower en0` == *On ]]

then

networksetup -setairportpower en0 off

else

networksetup -setairportpower en0 on

fi

6 replies
Question marked as Top-ranking reply

Jun 25, 2015 2:19 AM in response to Barney-15E

Some Macs have the WiFi port is not 'en1' as in the Barney-15E's script (ex: MacBook Pro Retina 15 with Yosemite).

So, the script will work for switch WiFi to ON only.

I think it's regular for new Apple laptops without Ethernet RJ45 port.


To solve the problem it should be define which en* port is WiFi in the system.


I used the Terminal command:

$ networksetup -listallhardwareports


and find my WiFi as 'en0' :


$ networksetup -listallhardwareports


Hardware Port: Wi-Fi

Device: en0

Ethernet Address: 12:00:7h:cb:c7:11


So the Barney-15E's beautiful script changed to:


if [[ `networksetup -getairportpower en0` == *On ]]

then

networksetup -setairportpower en0 off

else

networksetup -setairportpower en0 on

fi

Jul 19, 2014 7:57 AM in response to Paardeslager

Here is a way to do it.

Create an Automator Service that looks like the following:

User uploaded file

The code in the Run Shell Script action is this:

if [[ `networksetup -getairportpower en1` == *On ]]
then
  networksetup -setairportpower en1 off
else
  networksetup -setairportpower en1 on
fi


Save the Service with a short name like, “ToggleWiFi"

Then, open Keyboard System Preferences and add a Shortcut to the new Service you created.


To create the service, open Automator and create a New Service.

Set it to Service receives no input in any application

Drag in a Run Shell Script action from the Utilities library.

Copy and paste the above code into the action, replacing “cat"

Save the Service.


Open Keyboard System Prefs

Click on Shortcuts Tab.

Select Services from the category list.

Scroll down and find your Service and set the shortcut.

User uploaded file

Jul 19, 2014 6:47 AM in response to Esquared

Thanks for your answer.

I have problems with my hands (artrose) and typing some keys is easier and less painful for me than using a mouse or trackpad.

The solution in the MacWorld article is more or less the same as I've tried myself. This only seems to work as the Wi-Fi icon is the most left in the menubar. This isn't going to work for me because besides the Apple menulets I have several others.

But thanks anyway.

Jul 19, 2014 8:13 AM in response to Paardeslager

Thanks Esquared and Barney-15E.


I have created the Automator Services script with the Shell script and it works great.

I had to run it first in Automater to get it work, but I guess that's the way it goes.


Reading all those threads in the Apple Support Communities made me feel that I'm not the only one looking for this kind of a solution.

I hope this will also be a help for those other people.


I can now use Control-W to turn Wi-Fi on and off. Great!

Thanks a lot !

How to turn Wi-Fi on / off with a shortcut

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.