Skip to content

Instantly share code, notes, and snippets.

@indec
Created May 29, 2013 18:23
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 indec/5672523 to your computer and use it in GitHub Desktop.
Save indec/5672523 to your computer and use it in GitHub Desktop.
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