Skip to content

Instantly share code, notes, and snippets.

@inertia42
Last active February 20, 2024 02:53
Show Gist options
  • Save inertia42/ba7ef06b88facbf8e407a8ee81bd7d3d to your computer and use it in GitHub Desktop.
Save inertia42/ba7ef06b88facbf8e407a8ee81bd7d3d to your computer and use it in GitHub Desktop.
Switch AirPods Pro between noise cancelling and transparency mode with apple script for Monterey.
# Modified from https://gist.github.com/rossinek/c0807a6a08cbfbf3f14259c70d15e643
set airpodName to "AirPods Pro" # This item should be the name of your AirPods Pro
set soundName to "声音"
set ancName to "降噪"
set transparencyName to "通透模式"
# for English Users
# set soundName to "Sound"
# set ancName to "Noise Cancellation"
# set transparencyName to "Transparency"
tell application "System Events"
tell its application process "ControlCenter"
set menuBarItems to menu bar items of menu bar 1
repeat with mbi in menuBarItems
if name of mbi contains soundName then
set soundMenu to mbi
end if
end repeat
if soundMenu is not equal to "" then
click soundMenu
repeat until exists of checkbox 1 of scroll area 1 of window 1
delay 0.2
end repeat
repeat with ch in checkboxes of scroll area 1 of window 1 as list
if name of ch contains airpodName then
set airPodsToggle to ch
end if
end repeat
if airPodsToggle is not equal to "" then
if 1 is not value of airPodsToggle then
click airPodsToggle
return
end if
end if
repeat with ch in checkboxes of scroll area 1 of window 1 as list
if name of ch contains transparencyName then
set transparencyToggle to ch
end if
if name of ch contains ancName then
set ancToggle to ch
end if
end repeat
if transparencyToggle is equal to "" or ancToggle is equal to "" then
return
end if
if value of transparencyToggle is 1 then
click ancToggle
else
click transparencyToggle
end if
click soundMenu
end if
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment