Skip to content

Instantly share code, notes, and snippets.

@DASPRiD
Created December 13, 2013 14:47
Show Gist options
  • Save DASPRiD/7945362 to your computer and use it in GitHub Desktop.
Save DASPRiD/7945362 to your computer and use it in GitHub Desktop.
#!/bin/bash
CARD_INDEX=0
PROFILE_SPEAKERS='output:iec958-stereo'
PROFILE_HEADPHONES='output:analog-stereo'
CURRENT_PROFILE=$(LANG=C \
pactl list cards \
| grep -E '^Card #|Active Profile:' \
| sed ':a;N;$!ba;s/\(Card #[0-9]*\)\n/\1: /g' \
| grep "Card #$CARD_INDEX" \
| sed 's/^.*Active Profile: //' \
| xargs \
)
if [ "$CURRENT_PROFILE" == "$PROFILE_HEADPHONES" ]
then
amixer --card $CARD_INDEX sset IEC958 on
pactl set-card-profile $CARD_INDEX $PROFILE_SPEAKERS
amixer -D pulse set Master 1+ unmute
notify-send --expire-time=1000 --hint=int:transient:1 "Sound output switched to speakers"
echo "Sound output switched to speakers"
else
amixer --card $CARD_INDEX sset IEC958 off
pactl set-card-profile $CARD_INDEX $PROFILE_HEADPHONES
amixer -D pulse set Master 1+ unmute
notify-send --expire-time=1000 --hint=int:transient:1 "Sound output switched to headphones"
echo "Sound output switched to headphones"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment