OSX Audio Device - Select from CLI

Loren (mcint) October 27, 2022 [Terminal] #cli #macOS

I can now switch audio device from the command line.

I installed switchaudio-osx via homebrew, and defined this osx-audio convenience function, to show and switch outputs.

osx-audio() { 
    [[ $# -eq 0 ]] 
    	&& SwitchAudioSource -c
	|| SwitchAudioSource -s "$(SwitchAudioSource -a | fzf -q "$@")";

Basic usage looks like:

$ osx-audio
Built-In Output
$ osx-audio pro
[fzf: select Air Pods Pro/enter]

Brifely summarize more extensive use of the installed tool:

SwitchAudioSource [-c|-a] [-f [human|cli|json]]

Read as -c current device, or -a all devices.

And formats human default minimal, cli a compact csv, and json a readable and labeled format.