I would like to change sound output device (like option-clicking the speaker icon in the menubar) via script, but NOT through UI scripting, e.g., launching the System Pref panel.
UPDATE: Using @Mateusz solution below, here is an Applescript that, when launched, will give you a popup to select the desired audio output device:
set devices to do shell script "/Applications/Audiodevice/audiodevice output list"
set answer to choose from list (paragraphs of devices) with title "Audio Output" with prompt "Select a device" without multiple selections allowed
if answer is false then return
do shell script "/Applications/Audiodevice/audiodevice output " & quoted form of item 1 of answer
(Note: you need to put the audiodevice
file in /Applications
)
Best Answer
There's
audiodevice
command available from whoshacks.Usage:
audiodevice
list devices for input, output, and system audioaudiodevice <port>
display the audio device for the selected portaudiodevice <port> list
list available audio devices for the selected portaudiodevice <port> <device>
set the selected port to use the designated device ("internal" will select Internal Speakers or Headphones, whichever is active)