I've seen answers like these but what I'm trying to do is programmatically ALWAYS set the audio output to built-in speakers regardless of which row item the Mac is currently tuned to.
In the code below (cited from the above link), the user selects between items 3 and 4. We know that built in speakers are always item 1, so is there a simpler way to achieve this where you send a shell command to always set the audio output to Built-in speakers?
(*
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