deweller / switchaudio-osx

Change the audio source for Mac OS X from the command line.
Other
1.16k stars 88 forks source link

I can't get /usr/local/bin/SwitchAudioSource -t system -s 'Selected sound output device' to work. #34

Closed Nostravinci closed 2 years ago

Nostravinci commented 2 years ago

On Sound's Sound Effects panel (system), I want to use SwitchAudioSource to set Selected sound output device as the active option.

I am trying to use this:

/usr/local/bin/SwitchAudioSource -t system -s 'Selected sound output device'

…but it does not work.

What am I missing? Is it possible? Thanks for any help!

CodeBrauer commented 2 years ago

Could you post the ouput of the command:

/usr/local/bin/SwitchAudioSource -f json -a

fearoffish commented 2 years ago

This isn't my ticket, but I see the same using device_name, but device_id and device_uid work:

❯ SwitchAudioSource -at output -f json
{"name": "LC49G95T", "type": "output", "id": "104", "uid": "4C2D5370-0000-0000-FFFF-0104B5772278"}
{"name": "USB Audio CODEC ", "type": "output", "id": "64", "uid": "AppleUSBAudioEngine:Burr-Brown from TI              :USB Audio CODEC :4110000:1"}
{"name": "CalDigit Thunderbolt 3 Audio", "type": "output", "id": "70", "uid": "AppleUSBAudioEngine:CalDigit, Inc.:CalDigit Thunderbolt 3 Audio:3200000:1"}
{"name": "Scarlett Solo USB", "type": "output", "id": "50", "uid": "AppleUSBAudioEngine:Focusrite:Scarlett Solo USB:Y7G0UDK0644256:1,2"}
{"name": "MacBook Pro Speakers", "type": "output", "id": "91", "uid": "BuiltInSpeakerDevice"}
{"name": "EpocCam Microphone", "type": "output", "id": "77", "uid": "VirtualMicInputOutput:01"}

❯ SwitchAudioSource -s 'USB Audio CODEC' -t output
Could not find an audio device named "USB Audio CODEC" of type output.  Nothing was changed.

# Using id works
❯ SwitchAudioSource -i 64
output audio device set to "Device with ID: 64"

# Using uid works
❯ SwitchAudioSource -u "USB Audio CODEC"
output audio device set to "Device with UID: AppleUSBAudioEngine:Burr-Brown from TI              :USB Audio CODEC :4110000:1"

MacOS 12.1 (21C52) Apple M1 Pro Homebrew installed

fearoffish commented 2 years ago

Ahhh, I just noticed the extra space in the device name. Using device_name with the space works:

❯ SwitchAudioSource -u "USB Audio CODEC "
output audio device set to "Device with UID: AppleUSBAudioEngine:Burr-Brown from TI              :USB Audio CODEC :4110000:1"
fearoffish commented 2 years ago

I think rather than closing this, the whitespace should be trimmed when it shows devices?

deweller commented 2 years ago

That's a valid request. I see how that would have caused some confusion.

This looks like an edge case with this one specific audio output and not a general issue with the code.

fearoffish commented 2 years ago

I'd class this as validating input, but I can see how it's a rare case. To be fair, I'd normally just PR and fix it...but I'm at level 0 for the C language, so sorry. At least it's documented in the issues now.

fearoffish commented 2 years ago

and thanks for the application, I forgot to say! :)

deweller commented 2 years ago

You bet. I appreciate you contributing to understanding the issue.