I often plug my MacBook into a secondary display using HDMI (Samsung TV). While working, I like to popup a BTT Webview of a streaming video site, but the audio was always stuck to my MacBook and not playing through TV Speakers.
I would then select the Output device from the volume menu bar to change audio to Samsung TV. I decided to write a toggle for the Touch Bar to complete this audio output selection for me. Enjoy!
-- Applescript to toggle between two sound outputs by Line number, as they appear in the System Prefs. Sound Control Panel.
set output1 to 1 --change this to the actual 'line number' of your first output speaker
set output2 to 2 --change this to the actual 'line number' of your second output speaker selection
--the rest of the script will use these vales to toggle between the two
tell application "System Preferences"
reveal anchor "output" of pane id "com.apple.preference.sound"
tell application "System Events"
tell application process "System Preferences"
repeat until exists tab group 1 of window "Sound"
tell tab group 1 of window "Sound"
if (selected of row output1 of table 1 of scroll area 1) then
set selected of row output2 of table 1 of scroll area 1 to true
set selected of row output1 of table 1 of scroll area 1 to true
quit application "System Preferences"
Enjoying This Preset? PayPal.me/K2DesignLab