0

I want to create keyboard shortcut for Turning ON WiFi when it is turned OFF, and vice versa.

1

Step 1: Find out device ID of Wi-Fi

$networksetup -listnetworkserviceorder | grep Wi-Fi
(2) Wi-Fi
(Hardware Port: Wi-Fi, Device: en0)

In this case it is en0

Step 2: Create a "Quick Action" using Automator.app. Set "no input" in "workflow receives" in "any application". Drag and drop "Run Shell Script" and add the following shell script to the text field.

if ( networksetup -getairportpower en0 | grep -q Off ); then 
 echo "network is off. turning ON";
 networksetup -setairportpower en0 on 
else echo "network is ON. turning OFF"; 
 networksetup -setairportpower en0 off
fi

Save the file in automator as, say, wifi-toggle

Step 3: Set keyboard shortcut by going to Keyboard -> Shortcuts -> Services

Scroll down. Look under "General". You should see an entry for "wifi-toggle"

|improve this answer|||||
  • 2
    Not all WiFi map to en0 but this is a great start to scripting and works for most MacBook line out of the box. – bmike Jan 15 at 13:12
  • 1
    check this script also which is independent of ethernet port number. apple.stackexchange.com/a/276272/341892 – Udhy Jan 15 at 15:14

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