My AppleScript to choose sound output has broken in Monterey

Hello all,

This script was working in Big Sur.

I am trying the trial of UI Browser to try to figure this out, but I am failing.

Troubleshooting ideas on how to fix this?

tell application "System Events"
	tell process "ControlCenter"
		try
			click (first menu bar item whose title is "Sound") of menu bar 1
			tell scroll area 1 of group 1 of window 1
				click (first checkbox whose title contains "AirPods Max")
			end tell
		end try
	end tell
end tell

Thanks!

Sincerely,

Jim

Hi Jim, still on Mojave so I can’t help with UI scripting here.

However to switch sound output I’m using switchaudio-osx for some years now. But I have to admit that I have no idea where I got it from (probably homebrew). It could be this.

I’m using it to switch from headphones to a custom setup (found on the web) in order to let me continue to listen to the tracks that I’d like shazam to detect. Great tool and definitely more reliable than UI scripting (but of course I don’t know the background of your question).

Cheers!

1 Like

+1 for switchaudio-osx

1 Like

I will take a look at it. Can you install it without brew?

Yes, but you have to build it in XCode. I’ve never done this (still not started looking into XCode) but maybe someone who knows how to do it could build it for you?

1 Like

Hey Jim,

As Pete says you can make it yourself.

HomeBrew has it.

MacPorts has it (although it looks like it’s a version behind HB).

And there’s a downloadable one here (although it’s old and might not work on your system):

-Chris

1 Like

Thanks Pete, Chris and tjluoma. Your collective encouragement pushed me to figure SwitchAudioSource out.

I now have it installed, and it works well.

Thank you all!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.