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)


There's audiodevice command available from whoshacks.


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

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


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


To install open terminal and run brew install switchaudio-osx

To list all the sources for input / output run SwitchAudioSource -a

This will produce output similar to

External Microphone (input)
MacBook Pro Microphone (input)
External Headphones (output)
MacBook Pro Speakers (output)

To switch microphone to External Microphone issue following command

SwitchAudioSource -t input -s 'External Microphone'


  • 1
    This answer isn't any different from the highest voted answer by Mateusz Szlosek – Allan Feb 16 '20 at 5:35

Here is an AppleScript to do it with switchaudio-osx (just replace the XXXXXXX with the device name you can get from executing "SwitchAudioSource -a"):

on run {input, parameters}

    do shell script "/usr/local/bin/SwitchAudioSource -s 'XXXXXXXX'"

    return input
end run
  • I've replaced the path to point to /usr/local/bin instead of the versioned Homebrew directory. Otherwise the script will no longer work if switchaudio-osx gets updated. – nohillside Jan 29 '20 at 6:28
  • Thanks @nohillside!!! – Alejandro Corredor Jan 30 '20 at 14:22

You must log in to answer this question.

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