Last active
June 10, 2016 02:08
-
-
Save matmunn/7161dc49e3c4b6323aa28536b1662f49 to your computer and use it in GitHub Desktop.
Script to toggle sound output devices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
OUTPUTDEV=`cat ~/.bin/sound_device` | |
INPUTS=($(pacmd list-sink-inputs | grep index | awk '{print $2}')) | |
if [ $OUTPUTDEV = "Speakers" ] | |
then | |
# Persist the changes in our file | |
OUTPUTDEV="Headset" | |
echo $OUTPUTDEV > ~/.bin/sound_device | |
# Set the default mode for the card we're switching to | |
pactl set-card-profile 1 output:analog-stereo | |
# Set the default sink for all new streams to our headset | |
pactl set-default-sink alsa_output.usb-Plantronics_Plantronics_HD1-00.analog-stereo | |
# Move all current streams to the headset | |
for i in ${INPUTS[*]}; do pacmd move-sink-input $i alsa_output.usb-Plantronics_Plantronics_HD1-00.analog-stereo &> /dev/null; done | |
else | |
# We're changing back to line out speakers now | |
OUTPUTDEV="Speakers" | |
echo $OUTPUTDEV > ~/.bin/sound_device | |
# Mark sure the card is in surround sound mode | |
pactl set-card-profile 2 output:analog-surround-51 | |
# All future streams are to come through the line out | |
pactl set-default-sink alsa_output.pci-0000_00_1b.0.analog-surround-51 | |
# Move all current streams to the speakers | |
for i in ${INPUTS[*]}; do pacmd move-sink-input $i alsa_output.pci-0000_00_1b.0.analog-surround-51 &> /dev/null; done | |
fi | |
# Show a notification on GNOME so I know what happened | |
notify-send 'Audio Changed' "Audio has been changed to $OUTPUTDEV" --icon=dialog-information |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment