Hi,
For an autonomous sound installation I’m trying to write a script that connects to 2 Bluetooth headsets.
Because I didn’t find a way to do this in the command line, I’m trying to accomplish it with GUI scripting.
Thanks to all the good resources on this forum it’s working!
The way it works now is that the script clicks the ‘pair’ button of the first, and later the second line of Bluetooth devices in the System Preference panel.
But now there might be a third bluetooth device present in the exhibition space which messes up the script.
I thought it would be helpful if the script could take the name of the Bluetooth device into account, but I couldn’t get that to work yet.
I imagine some pseudo script as follows:
click button "Pair" of row containing "JABRA TALK"
One complication is that both headsets have the same name. But after successfully pairing, the button “Pair” changes into a (x) button, that might be a way to select only rows that have the “Pair” button.
This is the current script, where the connection to both headsets is made
tell application "System Events" to tell process "System Preferences"
set frontmost to true
delay 1
tell window "Bluetooth"
delay 0.1
tell scroll area 1
delay 0.1
tell table 1
delay 0.1
tell row 2 -- FIRST JABRA
delay 0.1
tell UI element 1
delay 0.1
tell button 1
delay 0.3
click
end tell
end tell
end tell
end tell
end tell
end tell
end tell
delay 5
tell application "Finder"
activate
delay 5
end tell
tell application "System Events" to tell process "System Preferences"
delay 0.5
set frontmost to true
delay 1
tell window "Bluetooth"
delay 0.1
tell scroll area 1
delay 0.1
tell table 1
delay 0.1
tell row 4 -- SECOND JABRA, AFTER THE FIRST IS PAIRED
delay 0.5
delay 0.1
tell UI element 1
activate
delay 0.3
UI elements
delay 0.5
tell button 1
delay 0.5
click
end tell
end tell
end tell
end tell
end tell
end tell
end tell
It would be nice to get some pointers for a more robust script!
Thanks you!
Elias