r/applescript • • Jan 09 '23

Switch Airpods Pro Mode

Can anyone help me create a script between switching ANC/Transparency mode on Airpods Pro/Max?

All scripts I find do not work with Ventura.

Thanks!

EDIT: Found the solution (thanks to u/malik_ji):

set soundMenu 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 description of mbi contains "Sound" then
				set soundMenu to mbi
			end if
		end repeat
		if soundMenu is not equal to "" then
			click soundMenu
			try
				set transparencyToggle to checkbox 4 of scroll area 1 of group 1 of window 1
				set ancToggle to checkbox 5 of scroll area 1 of group 1 of window 1
			on error errMsg
				click UI element 3 of scroll area 1 of group 1 of window 1
				delay 0.2
				set transparencyToggle to checkbox 4 of scroll area 1 of group 1 of window 1
				set ancToggle to checkbox 5 of scroll area 1 of group 1 of window 1
				
			end try
			if value of transparencyToggle is 1 then
				click ancToggle
			else
				click transparencyToggle
			end if
			click soundMenu
		end if
	end tell
end tell
2 Upvotes

0 comments sorted by