Created
September 22, 2018 04:49
-
-
Save greglamb/63060e873e9d64bc3730b30ac52507f0 to your computer and use it in GitHub Desktop.
Connect to Bluetooth devices via the Terminal
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
#!/usr/bin/osascript | |
(* | |
Usage: | |
./connect-bluetooth.applescript listall | |
./connect-bluetooth.applescript "Greg’s AirPods" | |
*) | |
on run argv | |
set DeviceName to item 1 of argv | |
activate application "SystemUIServer" | |
tell application "System Events" to tell process "SystemUIServer" | |
set bt to (first menu bar item whose description is "bluetooth") of menu bar 1 | |
click bt | |
if DeviceName is equal to "listall" then | |
repeat with btdevice in (get menu items of menu 1 of bt) | |
log btdevice | |
end repeat | |
key code 53 | |
else | |
if exists menu item DeviceName of menu 1 of bt then | |
tell menu item DeviceName of menu 1 of bt | |
click | |
tell menu 1 | |
if exists menu item "Connect" then | |
click menu item "Connect" | |
return "Connecting..." | |
else | |
key code 53 -- hit Escape to close BT menu | |
return "No connect button; is it already connected?" | |
end if | |
end tell | |
end tell | |
else | |
key code 53 -- hit Escape to close BT menu | |
return "Cannot find that device, check the name" | |
end if | |
end if | |
end tell | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment