Audio switching on the Mac

A handy walk through to add an audio output switcher and bind it to a key

Here is a handy walk through to add an audio output switcher and bind it to a key

Install switchaudio-osx

brew install switchaudio-osx

Get a list of all audio devices

/opt/homebrew/bin/SwitchAudioSource -a

Drop this script somewhere on your disk

#!/bin/sh
set -x

cmd="/opt/homebrew/bin/SwitchAudioSource"
current=$(${cmd} -c)
s=""
if [[ ${current} == "Display Audio" ]]; then
    s="CalDigit Thunderbolt 3 Audio"
elif [[ ${current} == "CalDigit Thunderbolt 3 Audio" ]]; then
    s="MacBook Pro Speakers"
elif [[ ${current} == "MacBook Pro Speakers" ]]; then
    s="Display Audio"
fi
${cmd} -s "${s}"
echo "Switched audio to ${s}"
osascript -e "display notification \"Switched audio to ${s}\" with title \"Audio Switcher\""

Create the shortcut

  • Open up Shortcuts and create a New Shortcut
  • Under categories search for "Run a shell script" (hint: scripting -> Run a shell script
  • Select your shell, set input to Input and pass Input to stdin.
  • In the text box put the full path to your script
  • Click the info button at top right
  • Under "Run With" select a key to use (I use Fn-F5)

Give it a try