Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shell script to drive https://github.com/deweller/switchaudio-osx from Alfred
#!/bin/bash
headphones="Generic USB Audio Device "
speakers="Display Audio"
arg=$1
if [ "${arg}" = "headphones" ]; then
target=${headphones}
elif [ "${arg}" = "speakers" ]; then
target=${speakers}
else
foo=$( /usr/local/bin/SwitchAudioSource -c )
if [ "${foo}" = "${headphones}" ]; then
target=${speakers}
arg="speakers"
else
target=${headphones}
arg="headphones"
fi
fi
for type in "output" "input" "system"; do
/usr/local/bin/SwitchAudioSource -t "$type" -s "$target" 2>&1 > /dev/null
done
/usr/local/bin/growlnotify --image /System/Library/PreferencePanes/Sound.prefPane/Contents//Resources/SoundPref.icns -name "Audio switcher" -m "Switched audio to $arg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment