I figured out how to connect and disconnect my AirPods with a macro and thought I'd post the steps for others, especially relative shell script novices like me.
- Install Homebrew by entering the following into the Terminal. More on Homebrew here.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Install the BluetoothConnector package by entering the following in Terminal:
brew install bluetoothconnector
- Run BlueTooth Connector by entering the following in Terminal:
BluetoothConnector
Since you didn't include a MAC address in the command, it will return an error message that includes MAC addresses for any Bluetooth device you've previously connected to. Copy the one for the device you want to connect too.`
- Create a new macro in KM, add whatever trigger you like, and add the Execute Shell Script action. In the box, enter the following. (Note for shell script novices: the was the part I wasn't sure about, but it turns out, to run a Homebrew package from a shell script, you need the full file path of the package. To find that, open a finder window, type Command-Control-G, and search for usr/local. Then poke around until you find the actual application--if that's the right word--not an alias.)
/usr/local/Cellar/bluetoothconnector/2.0.0/bin/bluetoothconnector [MAC address for your device]
The above will toggle the connection. If you would rather have separate macros to connect or disconnect, use these commands.
bluetoothconnector --connect [MAC address]
bluetoothconnector --disconnect [MAC address]
If you would like a notification when the device connects or disconnects, add --notify at the end of the command and in your Execute Shell Script action, change "ignore results" to "show results briefly."