Toggle Bluetooth Connection with Macro

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."

9 Likes

bluetoothconnector looks like a very useful tool, and one that I was not previously familiar with. Thanks for sharing!

1 Like

Exactly what I was looking for, thank you!

1 Like

I installed everything but the cellar folder doesn't exist :frowning:

Hello Johann (@johann85)

I think this is an issue that depends which type of Mac you have. As far as I am aware of the Cellar folder will not exist when your Mac has an M1 or M2 Processor from Apple …

The best what you can do is open the terminal and type which & the command (in this case bluetoothconnector) & submit by pressing enter …

terminal gives you the path to it …

Greetings from Germany :de:

Tobias

2 Likes