Here's how I did it. (Note: this solution requires familiarity with Terminal.app and the ssh
command)
- @Tetsujin's post above led me to this post which contained an Applescript that did the job. (Another comment mentioned that when designating an Airplay device, the separating line as an item!)
(*
Applescript to toggle between two sound outputs by Line number, ¬
as they appear in the Sound Control Panel. Based on code by ¬
Arthur Hammer http://apple.stackexchange.com/a/209434/85275
*)
set internal to 1 --internal speakers
set appletv to 3 --Follows internal speakers and separator line for Airplay devices
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.sound"
end tell
tell application "System Events"
tell application process "System Preferences"
repeat until exists tab group 1 of window "Sound"
end repeat
tell tab group 1 of window "Sound"
click radio button "Output"
if (selected of row internal of table 1 of scroll area 1) then
set selected of row appletv of table 1 of scroll area 1 to true
else
set selected of row internal of table 1 of scroll area 1 to true
end if
end tell
end tell
end tell
tell application "System Preferences" to quit
I stored this script in my Documents folder on the media-server Mac, as toggle_audio_output.scpt
- On the laptop side, I used Automator to create an App consisting of one action,
Run Shell Script
. The "script" was a one-line command,
ssh [email protected] osascript /Users/plex/Documents/toggle_audio_output.scpt
This logs into my server and executes the shell command osascript
which in turn executes my applescript.
Note that there are a lot of additional hoops to jump through to allow ssh
to log in without prompting for a password. I'm sure (?) there's an Applescript or Automator way to do something similar, and if anyone wants to suggest how, go for it.
I saved the Automator script (toggle_retsina_audio_output.app
) in ~/Applications, then dragged the icon into the Dock. Now, with a single click, I accomplish what I set out to do.