Watch system change (like bluetooth device just connected)

I'm trying to set a touchbar action to (dis)connect my bluetooth headphones. I'd like to toggle the alternate mode as soon as it (dis)connects, but I couldn't find a clean and efficient way to do it: my current script must check among every known bluetooth devices and see if the desired one is connected, every X seconds. More seconds leads to unresponsive results, less seconds leads to battery drain.

Is there any better way to do this? Didn't find anything here or Github.

Also, I was wondering if BetterTouchTool could use Launchagents to watch system wide changes, like this:

Example plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">

    <string>Smartcard reader</string>




Looks like it would be very efficient to trigger actions!


I haven't used such launch agents for bluetooth monitoring before, but if this works you could just call BTT from the referenced "script.bash" like this:

osascript -e "tell application \"BetterTouchTool\" to trigger_named \"SomeBluetoothThingConnected\""

This would then trigger a named trigger that can be configured in BTT:

In general I should add more such triggers directly in BTT. I'll work on that.


Thanks for you quick answer. I'm not experienced enough with BTT and bash to get all of this working together, but I'm glad to hear that it will be improved! Thanks again for your amazing work :slight_smile: Loving my touchbar now.