Switch audio output via command line on MacOS

0
5033
Switch audio output via command line on MacOS
Switch audio output via command line on MacOS

In this post, I will show you how to switch audio output via command line on MacOS.

To switch audio output, we will install and use the switchaudio-osx utility.

To install the utility, use Homebrew for the job.

$ brew install switchaudio-osx

Make sure to reload the shell (bash/zsh/fish…) after that.

The command SwitchAudioSource will be available in the PATH.

$ SwitchAudioSource
Please specify audio device.
Usage: /opt/homebrew/Cellar/switchaudio-osx/1.1.0/SwitchAudioSource [-a] [-c] [-t type] [-n] -s device_name | -i device_id | -u device_uid
  -a             : shows all devices
  -c             : shows current device

  -f format      : output format (cli/human/json). Defaults to human.
  -t type        : device type (input/output/system).  Defaults to output.
  -n             : cycles the audio device to the next one
  -i device_id   : sets the audio device to the given device by id
  -u device_uid  : sets the audio device to the given device by uid or a substring of the uid
  -s device_name : sets the audio device to the given device by name

To show current audio device:

$ SwitchAudioSource -c
Pete Houston’s AirPods

To show all audio devices:

$ SwitchAudioSource -a
HD Pro Webcam C920
Pete Houston’s AirPods
External Microphone
MacBook Pro Microphone
LG HDR 4K

To set audio device:

$ SwitchAudioSource -s "MacBook Pro Speakers"
output audio device set to "MacBook Pro Speakers"

That’s it! Now you know how to switch audio output via command line on MacOS.

Have fun!