Skip to content

Instantly share code, notes, and snippets.

@rossinek
Created March 15, 2021 08:46
Show Gist options
  • Save rossinek/c0807a6a08cbfbf3f14259c70d15e643 to your computer and use it in GitHub Desktop.
Save rossinek/c0807a6a08cbfbf3f14259c70d15e643 to your computer and use it in GitHub Desktop.
Toggle AirPods Pro active noise cancelling with apple script
set soundMenu to ""
set airPodsToggle to ""
set ancToggle to ""
set transparencyToggle to ""
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 "Sound" then
set soundMenu to mbi
end if
end repeat
if soundMenu is not equal to "" then
click soundMenu
set soundCheckboxes to checkbox of scroll area 1 of group 1 of window 1
repeat with ch in soundCheckboxes
if name of ch contains "AirPods" 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
set soundCheckboxes to checkbox of scroll area 1 of group 1 of window 1
repeat with ch in soundCheckboxes
if name of ch contains "Transparency" then
set transparencyToggle to ch
end if
if name of ch contains "Noise Cancellation" 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
@aleclarson
Copy link

aleclarson commented Aug 9, 2022

Monterey 12.5 – Opening the menu, but not toggling anything

System Events got an error: Can’t get group 1 of window 1 of application process "ControlCenter". Invalid index.

@inertia42
Copy link

Monterey 12.5 – Opening the menu, but not toggling anything

System Events got an error: Can’t get group 1 of window 1 of application process "ControlCenter". Invalid index.

Perhaps this script can solve your issue.
https://gist.github.com/inertia42/ba7ef06b88facbf8e407a8ee81bd7d3d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment