Forked from ieatfood/Connect Airpods.applescript
Last active
November 12, 2024 17:36
-
-
Save davidsharp/725fff254801592ea56c3870c158dc72 to your computer and use it in GitHub Desktop.
A xbar/bitbar wrapper around an Applescript to connect bluetooth devices, such as Airpods.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function pair(){ | |
osascript <<'END' | |
use framework "IOBluetooth" | |
use scripting additions | |
set blueToothDevice to "Buds Pro" | |
on getFirstMatchingDevice(deviceName) | |
repeat with device in (current application's IOBluetoothDevice's pairedDevices() as list) | |
if (device's nameOrAddress as string) contains deviceName then return device | |
end repeat | |
end getFirstMatchingDevice | |
on toggleDevice(device) | |
if not (device's isConnected as boolean) then | |
device's openConnection() | |
return "Connecting " & (device's nameOrAddress as string) | |
else | |
device's closeConnection() | |
return "Disconnecting " & (device's nameOrAddress as string) | |
end if | |
end toggleDevice | |
return toggleDevice(getFirstMatchingDevice(blueToothDevice)) | |
END | |
} | |
if [[ "$1" = "pair" ]]; then | |
pair | |
fi | |
echo "ᚼᛒ|bash=$0 param1=pair terminal=false" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment