Any way to change sound output device via Applescript or shell? 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 " &amp; quoted form of item 1 of answer


(Note: you need to put the audiodevice file in /Applications)
There's switchaudio-osx, command which needs to be compiled from sources or can be installed via homebrew (Xcode installation required):

brew install switchaudio-osx


Usage:

SwitchAudioSource [-a] [-c] [-t type] [-n] -s device_name



-a : shows all devices
-c : shows current device
-t type : device type (input/output/system). Defaults to output.
-n : cycles the audio device to the next one
-s device_name : sets the audio device to the given device by name