Paardeslager

Q: 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

Close

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

  • All replies
  • Helpful answers

  • by Esquared,

    Esquared Esquared Jul 19, 2014 3:32 AM in response to Paardeslager
    Level 6 (8,410 points)
    Mac OS X
    Jul 19, 2014 3:32 AM in response to Paardeslager

    Simply clicking on the wifi icon in the menubar isn't an option for you?


    In that case this approach might help: http://hints.macworld.com/article.php?story=2008101520293355

  • by Paardeslager,

    Paardeslager Paardeslager Jul 19, 2014 6:47 AM in response to Esquared
    Level 1 (0 points)
    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.

  • by Esquared,

    Esquared Esquared Jul 19, 2014 7:22 AM in response to Paardeslager
    Level 6 (8,410 points)
    Mac OS X
    Jul 19, 2014 7:22 AM in response to Paardeslager

    OK, check out the last three posts in this thread:

    How to create shortcut to turn on/off Wifi in Snow Leopard

     

    This looks the most promising:

    http://arsnovaproductions.wordpress.com

  • by Barney-15E,Solvedanswer

    Barney-15E Barney-15E Jul 19, 2014 7:57 AM in response to Paardeslager
    Level 8 (49,784 points)
    Mac OS X
    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:

    Screen Shot 2014-07-19 at 9.51.43 AM.png

    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.

    Screen Shot 2014-07-19 at 9.57.03 AM.png

  • by Paardeslager,

    Paardeslager Paardeslager Jul 19, 2014 8:13 AM in response to Paardeslager
    Level 1 (0 points)
    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 !

  • by ctdvng,

    ctdvng ctdvng Jun 25, 2015 2:19 AM in response to Barney-15E
    Level 1 (0 points)
    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