Skip to content

Instantly share code, notes, and snippets.

@frostworx
Last active August 10, 2020 06:13
Show Gist options
  • Save frostworx/2a1a84ea8098ddc207cc9f54793f5446 to your computer and use it in GitHub Desktop.
Save frostworx/2a1a84ea8098ddc207cc9f54793f5446 to your computer and use it in GitHub Desktop.
little (hotkey) script which toggles audio output between VR HMD headphones and regular speakers
#!/bin/bash
function PACtl {
LC_ALL=C /usr/bin/pactl "$@"
}
function getAvailablePAProfiles {
PACtl list | grep -E 'output.*stereo.*HDMI.*yes' | cut -d':' -f1,2 | awk '{$1=$1};1'
}
function setActive {
PACtl set-card-profile 0 "$1"
}
PROF1="$(getAvailablePAProfiles | head -n1)"
PROF2="$(getAvailablePAProfiles | tail -n1)"
ACTIVE_PROF="$(PACtl list | grep -E 'Active Profile.*output' | awk -F ': ' '{print $2}')"
if [ "$ACTIVE_PROF" == "$PROF1" ] ; then
setActive "$PROF2"
else
setActive "$PROF1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment