Switch Audio Source

Hey Johannes,

Please post the actual results of:

SwitchAudioSource -c

-Chris

➜ ~ SwitchAudioSource -a
Background Music (input)
Background Music (UI Sounds) (input)
MacBook Air Mikrofon (input)
USB Audio (output)
Background Music (output)
Background Music (UI Sounds) (output)
Externe Kopfhörer (output)
MacBook Air Lautsprecher (output)
Screen Record w/ Audio (output)

as you can see I use Background Music.app which complicates things a little. but even without the script doesn't work.

export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:$PATH;

currentOutput=$(SwitchAudioSource -c); echo $currentOutput

deviceExists=$(SwitchAudioSource -a | awk '/Scarlett Solo USB \(output\)/ { print }')

if [ "$currentOutput" = 'Scarlett Solo USB' || "$currentOutput" = 'MacBook Air Lautsprecher' ]; then
	
	SwitchAudioSource -s 'Externe Kopfhörer'
			
else
	if [ "$deviceExists" != '' ]; then
		SwitchAudioSource -s 'Scarlett Solo USB'
	else
		SwitchAudioSource -s 'MacBook Air Lautsprecher'

fi

It helps when you use the correct syntax:

if [ "$currentOutput" = 'Scarlett Solo USB' ] || [ "$currentOutput" = 'MacBook Air Lautsprecher' ]; then

:sunglasses:

-Chris

Hi all,

Thanks for a great thread. I've got switching working using switchAudioSource. I'd like to take another step and add an additional feature that'll make this even more valuable, at least for me.

Hoping I can change the sound icon in the menubar to indicate which output is selected. I'm toggling between 'USB Audio Device' & 'SDAC ', so maybe in my case I could use 'USB' & 'SDAC'.

This action could happen within the existing if/then/otherwise structure, wondering if anyone has an idea how to implement?

TIA,
other chris

Hey Chris,

No can do.

There might be a sound-switching utility that can, but Apple's stock sound menu can't.

-Chris

Hey Chris,

I don’t know if you ever found a workaround for your case use, but Rogue Amoeba’s SoundSource allows to to see individual menu bar icons for all apps that are currently outputting audio, as well as see what the current output device is. This would let you see what device is your current output selection.

SoundSource 5 by Rogue Amoeba

They have a demo version so you can see if you like it or not.

I don't see anything about it being scriptable...

-ccs

Yea I was only ever able to script it using System Events and GUI, but it would at least let him see unique icons for his audio settings in the menu bar. Perhaps he could use it in conjunction with his switchAudioSource setup.

1 Like

In case it helps, Rogue Amoeba have just added Shortcuts support to SoundSource. My first attempt at automating this is here...

2 Likes

I was thrilled to see this new feature when they rolled it out this week and immediately started using it.

Your macros look very well designed, I’ll have to check them out more when I’m back at my computer!

1 Like

Me too! :nerd_face: It's taken me a few days to have the time to write it up.

And that's kind of you to say. As ever, I'd really welcome your expert feedback, Chris - it's always much appreciated :slight_smile:

For those that don’t have Rogue Amoeba’s SoundSource but want to switch to any output listed in the Sound Preferences (including AirPlay sound outputs, e.g., HomePod, Apple TV), consider trying this macro: Set Sound Output

3 Likes