Turn Wifi off/on with a single key?
Thanks to budakpisang for this:
In Terminal, run
networksetup -listnetworkserviceorder | sed -n '/Wi-Fi/s|.*Device: \(.*\)).*|\1|p'

to get your WiFi network device (usually it's en0 or en1, depending on the Mac model you have). Substitute it for en1 in the following steps
You can turn wifi off and on with these commands
networksetup -setairportpower en1 off
networksetup -setairportpower en1 on

Here's a one-liner to toggle between on and off
networksetup -getairportpower en1 | grep &quot;On&quot; &amp;&amp; networksetup -setairportpower en1 off || networksetup -setairportpower en1 on

Create a keyboard shortcut that runs a shell command

Start Automator, and create a new Service.

Set &quot;Service receives selected: to &quot;no input&quot; in &quot;any application&quot;.

Add an action named &quot;Run Shell Script&quot;. It's in the Utilities section of the Actions Library.

Insert the bash command you want into the text box and test run it using the Run button (top right). It should do whatever the script does (off, on or toggle), and there should be green ticks below the Action.

Save it, giving it a service name you can remember.

Go to System Preferences -&gt; Keyboard, and go to the Shortcuts tab

Go to the Services section, and scroll down to General - you should find your service there. If you select the line, you can click &quot;add shortcut&quot; and give it a keyboard shortcut.