switchaudio-osx
switchaudio-osx copied to clipboard
unable to switch to AirPlay output 'devices'
I'm unable to switch to my airplay 'speakers'

$ SwitchAudioSource -a
Built-in Microphone (input)
Built-in Output (output)
$ SwitchAudioSource -t output -s "Garage"
Could not find an audio device named "Garage" of type output. Nothing was changed.
+1
this used to work... +1
But: It still let's you switch if you call -s and the exact name of the device! (use "\ " for spaces) Just switch to your airplay device using syspreferences and run -c and it will also tell you the current device Edit: This strangly works just as long as system prefercenses are open...
I don't think it has anything to do with System Preferences being open. At first I thought I had it working for a second too, but really what I see now (with macOS Sierra) is:
SwitchAudioSource -cwill report the AirPlay device if it was manually selected in macOS.- Trying to switch to it (
SwitchAudioSource -s "Downstairs Speakers") won't work (Could not find an audio device named "Downstairs Speakers" of type output. Nothing was changed.) - However if I already have an AirPlay device selected manually, switching away from that device (
SwitchAudioSource -s "Built-in Output") actually keeps the AirPlay device selected but then also enables* the second device, at least according to the screenshot below. - Then it appears that switching to an AirPlay device works (
SwitchAudioSource -s "Downstairs Speakers"now yieldsoutput audio device set to "Downstairs Speakers") but in reality the AirPlay device was already selected.
- Note that when playing audio with this configuration, it does not come out of both devices. As far as I can tell, there's no other way to achieve this UI state in macOS, so this may be a macOS bug?
Any thoughts @deweller?
I don't use AirPlay speakers, so naturally I haven't encountered this bug.
I'd be happy to review a patch if anyone is able to fix it.
Also not working for AirPlay devices for me. OSX El Capitan + latest SwitchAudio version from brew (as of today).
+1
Any news on this? 😟
Same problem here on High Sierra. Any news? Looks like AirPlay outputs are treated differently. Just to confirm: if my AirPlay receiver has been selected using the menu, I can run -c AirMusic-Box and it confirms, but when I run the same command with any other device selected it claims the device is unknown. Unfortunately I am a newbie to XCode and it has been a while for me to program in C but I will try insert some diagnostic code and find out... Maybe the airport receivers have a different device type than "output"...
Whats more so interesting is that say -a '?' also does not show airplay speakers (at least with my configuration using shairport-sync). Therefore, Apple themselves also seem to have not avoided this problem.
Even say --audio-device=? does not find available airplay devices on Mac OS [High] Sierra. One has to connect them manually to become available. Once connected and selected, streaming interactively with say to an airplay speaker doesn't work as expected.
Same issue here :( can't use this with AIrplay speakers
Same here! This project doesn't seem supported anymore, but is anyone created a patch?
As @deweller said, the developers don't use AirPlay. Someone needs to write the code.
Not the greatest solution, but a possible workaround with AppleScript. I combined 2 AppleScripts, based on this tutorial: http://apetronix.com/switch-audio-outputs-with-a-keyboard-shortcut-on-os-x/ HDMI and AirSpeaker are stand-ins.
Set the currentAudioSource to (do shell script "/usr/local/Cellar/switchaudio-osx/1.0.0/SwitchAudioSource -c") if currentAudioSource is equal to "HDMI" then tell application "System Events" tell process "SystemUIServer" click (menu bar item 1 of menu bar 1 whose description contains "Volume") set Airplay to menu 1 of result click ((menu item 1 where its name starts with "AirSpeaker") of Airplay) end tell end tell else do shell script "/usr/local/Cellar/switchaudio-osx/1.0.0/SwitchAudioSource -s "HDMI"" end if
+1
+1 BIG SUR 11.0.1 (20B29)
The great workaround from @timonvanhasselt sadly don't work under Big Sur.
I don't use AirPlay speakers, so naturally I haven't encountered this bug.
I'd be happy to review a patch if anyone is able to fix it.
I will have a try....
Thanks @alanhg!
I was originally gonna use switchaudio-osx but then AppleScript can do it natively:
set HomePod to "Bedroom"
tell application "System Events"
tell application process "ControlCenter"
set soundMenu to menu bar item "Sound" of menu bar 1
tell soundMenu to click
set soundCheckbox to checkbox 1 of scroll area 1 of group 1 of window "Control Center" whose title contains HomePod
set soundCheckboxValue to value of soundCheckbox
tell soundCheckbox to click
tell soundMenu to click
end tell
end tell
Great, thank you @demyxco
Attention:
The Window and menu bar items are localized. In German I had to change Sound and Control Center:
set HomePod to "Bedroom"
tell application "System Events"
tell application process "ControlCenter"
set soundMenu to menu bar item "Ton" of menu bar 1
tell soundMenu to click
set soundCheckbox to checkbox 1 of scroll area 1 of group 1 of window "Kontrollzentrum" whose title contains HomePod
set soundCheckboxValue to value of soundCheckbox
tell soundCheckbox to click
tell soundMenu to click
end tell
end tell
Here is another one that uses System Preferences but you only changed the "Bedroom" string:
tell application "System Preferences"
reveal anchor "output" of pane id "com.apple.preference.sound"
end tell
tell application "System Events" to tell process "System Preferences"
tell table 1 of scroll area 1 of tab group 1 of window 1
select (row 1 where value of text field 1 is "Bedroom")
end tell
end tell
quit application "System Preferences"
I found that I didn't have the energy to learn C and how to release the new package, so I decided to use AppleScript and Shell.
it works.

Any user who uses Alfred can download this workflow. Easy to switch to any audio include airplay.
https://github.com/alanhg/alfred-workflows/tree/master/switch-audio
@alanhg is the source for that available?
I took the script folks here have shared and enhanced it to make it more reliable to wait for the volume menu to open before switching to the airplay speaker.
I also attached it to a hotkey so I can simply press ⌘ + ' to trigger the switch.
set soundOutputName to "Dining Room"
tell application "System Events"
tell application process "ControlCenter"
-- Open Sound menu
set soundMenu to menu bar item "Sound" of menu bar 1
tell soundMenu to click
-- Select specified output
repeat until exists checkbox 1 of scroll area 1 of group 1 of window "Control Center" whose title is equal to soundOutputName
end repeat
set soundCheckbox to checkbox 1 of scroll area 1 of group 1 of window "Control Center" whose title is equal to soundOutputName
tell soundCheckbox to click
-- Close Sound menu
tell soundMenu to click
end tell
end tell
https://github.com/alphabt/macos-automations/tree/master/Set%20Sound%20Output has more detail on how to setup the hotkey using macOS's Automator workflow.
@alanhg is the source for that available?
of course
@alanhg is the source for that available?
of course
Where? I only see the alfredworkflow file.
@alanhg is the source for that available?
of course
Where? I only see the alfredworkflow file. Sorry, Alfred workflow is an archive file, only works in alfred.
For Apple Script, you can view the readme. I have posted link.
https://gist.github.com/alanhg/21f7fd110e0bdac1d0cce66ca40e78ea
I have similar issue with my SDAC. Figured out, what actual name is "SDAC ", with space, for some reason.