6

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)

2

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)
16

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
  • I'm trying to install this using homebrew with brew install switchaudio-osx but it reports: switchaudio-osx: A full installation of Xcode.app is required to compile this software. Installing just the Command Line Tools is not sufficient. Xcode can be installed from the App Store. Error: An unsatisfied requirement failed this build. Any way around this? – Dan Oct 28 '15 at 10:42
  • The build procedure of switchaudio-osx relies on dependencies etc. defined in Xcode (the application). Somebody who knows his way around Xcode better than I do could probably extract them into a Makefile. – nohillside Oct 28 '15 at 13:53
  • 1
    @Ze'ev Or you evaluate the risks involved and get the version I just compiled out of my Dropbox dl.dropboxusercontent.com/u/3188370/SwitchAudioSource – nohillside Oct 28 '15 at 13:57
  • 1
    @Ze'ev I've made a shellscript that automates the compilation/installation by downloading mas, then xcode, then switchaudio-osx. This way you benefit from updated source-code and not a pre-compiled binary that potentially is unsafe or falls out of date. See: install-switchaudio.sh – Paul Nelson Baker Jan 30 '18 at 17:30
  • brew install switchaudio-osx! – Dan Jan 30 '18 at 23:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .