bluetooth-changed.sh
#!/bin/bash
CONNECTED=`system_profiler SPBluetoothDataType | grep -B 2 "Connected: Yes"`
XM4=`echo $CONNECTED | grep XM4`
XM2=`echo $CONNECTED | grep XM2`
AIRPODS=`echo $CONNECTED | grep AirPods`
if [ ! -z "$XM4" ] || [ ! -z "$XM2" ] || [ ! -z "$AIRPODS" ];
then
/usr/bin/curl --header "Content-Type: text/plain" --request POST --data "OFF" http://192.168.1.17:8090/rest/items/WerkkamerSpeakers
else
/usr/bin/curl --header "Content-Type: text/plain" --request POST --data "ON" http://192.168.1.17:8090/rest/items/WerkkamerSpeakers
fi
~/Library/LaunchAgents/bluetooth-watcher.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>bluetooth-watcher</string>
<key>KeepAlive</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/Users/jidserda/scripts/bluetooth-changed.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Library/Preferences/com.apple.Bluetooth.plist</string>
</array>
</dict>
</plist>
activate plist with launchctl load ~/Library/LaunchAgents/bluetooth-watcher.plist