I want to use the F5 key on my MBP to turn on Wifi with a single hit on the keyboard and turn it off again with a single hit using F6. Is this possible? I've tried to do it under Preferences/Keyboard/Keyboard Shortcuts but I can't add F5 (not by typing and not by hitting that button). That button seems to be dedicated for the illumination of the keyboard. How can I change these settings so that I can have my fast function key at my disposal.
Since no has posted a solution, here's one way to do it, expanding upon WZZZ's answer above should actually be:
networksetup -setairportpower en1 off
networksetup -setairportpower en1 on
where en1 is the Interface Name of your Wi-Fi device. It was en1 on my laptop, but you can check and be sure using:
Also, you can toggle it if you grep the current state using -getairportpower first. Here's the full command to toggle Wi-Fi state on and off (the whole thing is one long line):
networksetup -getairportpower en1 | grep "On" && networksetup -setairportpower en1 off || networksetup -setairportpower en1 on
But typing it every time into Terminal is no good, so here's how you create a keyboard shortcut that runs a shell command:
1. Start Automator, and create a new Service.
2. Set "Service receives selected: to "no input" in "any application".
3. Add an action named "Run Shell Script". It's in the Utilities section of the Actions Library.
4. 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.
5. Save it, giving it a service name you can remember.
6. Go to System Preferences -> Keyboard, and go to the Shortcuts tab
7. Go to the Services section, and scroll down to General - you should find your service there. If you select the line, you can click "add shortcut" and give it a keyboard shortcut.
The shortcut key will now trigger whatever command you set up earlier, no matter what app you're in, but shortcuts from the app take priority (so if your hotkey clashes with a hotkey in the app you're currently running, the app's hotkey will trigger).
Also, I don't think you can use any of the function keys. I don't know why, but I've never had those ever work, even with the Fn key. Command Shift A or something like that works fine.