Create keyboard shortcuts to manage your Bluetooth settings (feat. Mac’s Automator)
I deal with Bluetooth settings so often that it’s become a nuisance: when I start my work laptop and connect my headphones, when I need to switch to earphones, or when I’m done with work and switch to my personal laptop or phone. These connections get intertwined as well, often resulting to connecting to the wrong device and whatnot.
By the 127th time this has happened, the efficiency-loving (read: lazy) software dev in me finally asked myself: Is there a better way of doing this? And after some tinkering, I got my answer in the form of… keyboard shortcuts.
This is a walkthrough of implementing just that. A quick summary of what we need to do:
- Script a command we can execute via the terminal
- Create a Quick Action via Automator to run said script
- Tie a keyboard shortcut to the Quick Action
💡 Note: This walkthrough was done using a Mac running on Big Sur, with xcode and brew previously installed. Expect some differences between operating systems — you must be using Catalina 10.15 at the least — and ensure the two tools are already available or you’re able to install them.
Having said all that: Let’s get to it.
1. Script a command
For this step, we need to open our Terminal to install blueutil via Homebrew:
brew install blueutil
blueutil is a handy package originally written by Frederick Seiffert and is now maintained by Ivan Kuchin (props to both! 🙏). After installing, check if it works by running these commands in the Terminal:
# This turns your Bluetooth onblueutil -p on
# This lists all your paired devices
# Note the name of the device you want to connect toblueutil --paired> sample output:
> address: 1x-xx-xx-xx-xx-97, not connected, not favourite, paired, name: "WH-1000XM3", recent access date: 2022-08-19 18:14:28 +0000
> address: 5x-xx-xx-xx-xx-46, not connected, not favourite, not paired, name: "Macaroni", recent access date: 2022-08-19 17:56:51 +0000# Now try connecting to the device using its nameblueutil --connect "WH-1000XM3"# If this works, you're good for step #2! ✅
2. Create a Quick Action
A necessary step before this: Go to System Preferences > Security & Privacy > Privacy and choose Accessibility from the left. You need to allow Finder and Automator to run actions for you, otherwise Automator-initiated scripts won’t be allowed by your system.
Now that that’s settled, open Automator > click New Document > choose Quick Action.
In the available actions, search for Run Shell Script and drag it towards the workflow area. Make sure that Workflow receives no input in the options above.
Time to paste the script we tested in the Terminal, and click Run on the upper right side! But wait—this error pops up after:
To avoid this, go back to the Terminal and run
which blueutil. Copy the output for that command (it’s something like
/usr/local/bin/blueutil) and use it to replace
blueutil in the Automator script. You can see that it should now work:
Save your Quick Action (⌘Cmd + S) and give it a recognizable name.
3. Tie a keyboard shortcut
Now that we have our Quick Action, it’s time to knot loose ends by giving it a keyboard shortcut. Go to System Preferences > Keyboard > Shortcuts, and click Services on the left side. Scroll to the bottom to see your recent Quick Actions and click Add Shortcut to key in your preferred shortcut. (I would suggest not using popular ones that can override/confuse you, which is also why I favored using ^Ctrl instead of ⌘Cmd.)
And that’s it! You can now whiz away your Bluetooth preferences with just a few clicks. ⚡️
Is the effort in writing this walkthrough proportional to how helpful people may find it? It’s just about managing Bluetooth settings, after all.
But if you get resourceful enough, you may find other workflows you can shortcut using the same steps above. For devs out there, anything you run too often in the Terminal can be a keyboard shortcut (although aliases may be a better first-line solution).
It’s not limited to running scripts in the terminal either—if you check Automator’s actions, there are other steps you can use to construct your workflow, including managing files on Finder or launching other apps.
Maybe it’s time to rethink which daily rote tasks can be replaced with shortcuts. 🤖 Happy automating!
Credits to the following:
- How to enable Bluetooth in Mac with shortcut or command line answer by Vignesh Raja (2018)
- How to Security > Privacy settings for a “Watch Me Do” QuickAction in Automator answer by Dan (2022)
- Frederick Seiffert and Ivan Kuchin for blueutil