I am brand new here and I have an additional clarification or need additional help for an issue from this thread – Applescript: "can't get tab group 1 of window" (El Capitan)
In my preference pane, in addition to Headphones and Digital out, I also have 2 apple monitors and would like the option of selecting one of them as out put (namely the first one in the list).
Basically I need help with adjust his solution to be able to select the third row or first monitor as sound output. Or a way to accomplish this without knowing how to edit AppleScript for a different setup.
Best Answer
With a little experimentation on Arthur Hammer's script I discovered that the lines
set deviceselected to "xyz"
appear to be just visual feedback whilst in Script Editor & don't seem to be part of the actual functionality.The actual switching appears to be just between 2 chosen lines in the Control Panel; so, if you just need to switch between any 2 outputs, then you can just use the row numbers.
In this example I've lifted them out to be variables, so you don't need to delve in the script to change the required lines…
As you have more than 2 outputs, the first time you switch it will not necessarily go from/to the correct device, but will after that.
For example, if you wanted to switch between outputs 3 & 4, yet 2 was currently selected, the first change would be from "not 3" as opposed to "is 3" [hope you understand that convoluted explanation]
Maybe a little pictorial clarification - using the above script with outputA = 3 & outputB = 4, I can now switch between Digital Out & TonePort UX2.
One more note - the line numbers do not have to be consecutive, I could just as easily switch between Internal Speakers & TonePort by using lines 1 & 4.