2

I have a Mac (running Catalina) dedicated as a media server, running Plex and Spotify. I'd like to be able, from my Mac laptop, to simply click something and switch the remote Mac's audio output setting from its internal speakers to 'Bat Cave', my gen 4 Apple TV.

Any thoughts about how to accomplish this? I'm more at home with Unix shell scripting than with AppleScript or Automator, but any solution, including hybrid, would be great.

Chap
  • 1,234
  • 1
    See - https://apple.stackexchange.com/questions/217148/using-apple-script-to-manage-sound-output-selection [afaik, you'd have to run this on the remote Mac itself, because of the requirement for GUI scripting.] – Tetsujin Apr 13 '22 at 15:54

1 Answers1

2

Here's how I did it. (Note: this solution requires familiarity with Terminal.app and the ssh command)

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

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

Chap
  • 1,234