Skip to content

Instantly share code, notes, and snippets.

@wisq
Created April 28, 2023 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wisq/afcee5f024d6c95bc351e7abebcf5962 to your computer and use it in GitHub Desktop.
Save wisq/afcee5f024d6c95bc351e7abebcf5962 to your computer and use it in GitHub Desktop.
#!/bin/sh
SAS='/opt/brew/bin/SwitchAudioSource'
DOCK='CalDigit Thunderbolt 3 Audio'
EXT_MIC='External Microphone'
EXT_PHONES='External Headphones'
HEADSET='WH-1000XM3'
MAC_MIC='MacBook Pro Microphone'
MAC_SPEAKERS='MacBook Pro Speakers'
set -e
has_device() {
$SAS -t all -a | grep -q "$1"
}
set_input() {
$SAS -t input -s "$1"
}
set_output() {
$SAS -t output -s "$1"
set_system "$1"
}
set_system() {
$SAS -t system -s "$1"
}
if has_device "$DOCK"; then
set_input "$DOCK"
set_output "$DOCK"
elif has_device "$HEADSET" && has_device "$EXT_MIC"; then
set_input "$EXT_MIC"
set_output "$HEADSET"
else
input=`$SAS -t input -c`
output=`$SAS -t output -c`
if [ "$input" = "$HEADSET" ]; then
set_input "$MAC_MIC"
fi
if [ "$output" = "$EXT_PHONES" ]; then
set_output "$MAC_SPEAKERS"
else
set_system "$output"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment