Any way to change sound output device via Applescript or shell?

Solution 1:

There's audiodevice command available from whoshacks.

Usage:

  • audiodevice list devices for input, output, and system audio
  • audiodevice <port> display the audio device for the selected port
  • audiodevice <port> list list available audio devices for the selected port
  • audiodevice <port> <device> set the selected port to use the designated device ("internal" will select Internal Speakers or Headphones, whichever is active)

Solution 2:

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