Skip to content

Instantly share code, notes, and snippets.

@xcv58
Created December 25, 2022 23:58
Show Gist options
  • Save xcv58/9dbfdedf89b3f60fe2d5600e1ece13af to your computer and use it in GitHub Desktop.
Save xcv58/9dbfdedf89b3f60fe2d5600e1ece13af to your computer and use it in GitHub Desktop.
AppleScript switch to AirPods
set deviceName to "AirPods 2021"
tell application "System Events" to tell process "Control Center"
set i to 1
repeat with anElement in menu bar items of menu bar 1
if description of anElement is "Sound" then
exit repeat
end if
set i to i + 1
end repeat
click (menu bar item i) of menu bar 1
end tell
delay 0.5
tell application "System Events" to tell process "Control Center"
set i to 1
repeat with anElement in checkbox of scroll area 1 of group 1 of window 1
set identifier to value of attribute "AXIdentifier" of anElement
if identifier contains deviceName then
exit repeat
end if
set i to i + 1
end repeat
tell its window "Control Center" to click checkbox i of scroll area 1 of group 1
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment