• Skip to main content
  • Skip to primary sidebar

Ravi Shankar

Tweaking Apps

  • Swift
  • Tech Tips
You are here: Home / Automator / Turn on/off Wifi using Keyboard shortcut

Turn on/off Wifi using Keyboard shortcut

June 6, 2021 By Ravi Shankar

Mac users can turn on/off Wifi using option available as part of the Menu bar.

Wifi Menu bar option

Add quick action in Automator app

Launch Automator app on your mac and choose Quick Action.

Automator – Quick Action

Choose action as “Run Shell Script” then set Workflow receives to “no input” and set it to run for for any application and select an image for your action.

Then under the run script window add the following script.

set_wifi_on_or_off() {
  networksetup -getairportpower en${n} | grep ": ${1}";
  if test $? -eq 0;
  then
    echo WiFi interface found: en${n};
    eval "networksetup -setairportpower en${n} ${2}"
    return 0;
  fi
  return 1;
}

for n in $(seq 0 10);
do
  if set_wifi_on_or_off "On" "off"; then break; fi;
  if set_wifi_on_or_off "Off" "on"; then break; fi;
done

You can test the above script using “Run” option and check if Wifi settings turned On or Off based on the current state. Save this quick action by providing a name as “Wifi”

Assign a keyboard shortcut for quick action

Launch Keyboard preferences using System preferences and navigate to Shortcuts tab.

Keyboard Preferences

The newly added Wifi quick action will be available under Services. Now assign a keyboard shortcut for this action.

Note :- Make sure to select 3 letters or more keyboard combination for your shortcut. Sometimes other apps might be using the same set of key combination and this would prevent launching the Automator action.

References

Filed Under: Automator, Mac, Tips Tagged With: Automator, Keyboard Shortcut, Mac

Primary Sidebar

TwitterLinkedin

Recent Posts

  • How to block keywords in Jio broadband
  • How to disable opening an app automatically at login in Mac
  • How to set preferred Wifi network on Mac
  • Attribute Unavailable: Estimated section warning before iOS 11.0
  • How to recover Firefox password from Time Machine backup

Pages

  • About
  • Privacy Policy
  • Terms and Conditions

Copyright 2022 © rshankar.com

Terms and Conditions - Privacy Policy