switchaudio-osx icon indicating copy to clipboard operation
switchaudio-osx copied to clipboard

unable to switch to AirPlay output 'devices'

Open arkarkark opened this issue 8 years ago • 58 comments

I'm unable to switch to my airplay 'speakers'

image

$ 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.

arkarkark avatar Mar 12 '16 18:03 arkarkark

+1

philfreo avatar Aug 21 '16 22:08 philfreo

this used to work... +1

s00500 avatar Oct 29 '16 11:10 s00500

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...

s00500 avatar Oct 29 '16 11:10 s00500

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 -c will 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 yields output audio device set to "Downstairs Speakers") but in reality the AirPlay device was already selected.
screenshot 2016-12-27 16 17 47
  • 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?

philfreo avatar Dec 27 '16 21:12 philfreo

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.

deweller avatar Dec 29 '16 13:12 deweller

Also not working for AirPlay devices for me. OSX El Capitan + latest SwitchAudio version from brew (as of today).

lfilho avatar Apr 26 '17 12:04 lfilho

+1

Buadhai avatar Dec 14 '17 00:12 Buadhai

Any news on this? 😟

bermann avatar Dec 22 '17 23:12 bermann

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"...

hightechfreak avatar Dec 31 '17 15:12 hightechfreak

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.

rien333 avatar Jan 31 '18 13:01 rien333

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.

mloeschner avatar Jun 25 '18 16:06 mloeschner

Same issue here :( can't use this with AIrplay speakers

raptor235 avatar Aug 22 '18 20:08 raptor235

Same here! This project doesn't seem supported anymore, but is anyone created a patch?

fharper avatar Jan 03 '19 17:01 fharper

As @deweller said, the developers don't use AirPlay. Someone needs to write the code.

zuckschwerdt avatar Jan 03 '19 18:01 zuckschwerdt

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

timonvanhasselt avatar Feb 05 '20 08:02 timonvanhasselt

+1

samlin39 avatar Nov 13 '20 17:11 samlin39

+1 BIG SUR 11.0.1 (20B29)

samlin39 avatar Nov 13 '20 17:11 samlin39

The great workaround from @timonvanhasselt sadly don't work under Big Sur.

Suplanus avatar Nov 16 '20 05:11 Suplanus

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....

alanhe421 avatar Dec 09 '20 14:12 alanhe421

Thanks @alanhg!

deweller avatar Dec 09 '20 17:12 deweller

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

demyxco avatar Dec 28 '20 18:12 demyxco

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

Suplanus avatar Jan 06 '21 13:01 Suplanus

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" 

demyxco avatar Jan 06 '21 17:01 demyxco

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.

image

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

alanhe421 avatar Feb 12 '21 03:02 alanhe421

@alanhg is the source for that available?

kbd avatar Apr 09 '21 19:04 kbd

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.

alphabt avatar Apr 09 '21 19:04 alphabt

@alanhg is the source for that available?

of course

alanhe421 avatar Apr 10 '21 07:04 alanhe421

@alanhg is the source for that available?

of course

Where? I only see the alfredworkflow file.

kbd avatar Apr 10 '21 13:04 kbd

@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

alanhe421 avatar Apr 10 '21 14:04 alanhe421

I have similar issue with my SDAC. Figured out, what actual name is "SDAC ", with space, for some reason.

nvrmindu avatar Jun 01 '21 13:06 nvrmindu