Skip to content

Instantly share code, notes, and snippets.

@davideicardi
Last active February 2, 2020 10:05
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 davideicardi/999b8a3bb310e5a2aa90404918cb5942 to your computer and use it in GitHub Desktop.
Save davideicardi/999b8a3bb310e5a2aa90404918cb5942 to your computer and use it in GitHub Desktop.
Switch audio scripts bash script for Ubuntu
#!/bin/bash
set -e
NEW_SOURCE=1
DEFAULT_SOURCE=`pacmd list-sources | grep '* index' | cut -f5 -d' '`
if [ $DEFAULT_SOURCE -eq 1 ]
then
NEW_SOURCE=0
fi
pacmd set-default-source ${NEW_SOURCE}
pacmd list-source-outputs | grep index | while read line
do
pacmd move-source-output `echo $line | cut -f2 -d' '` ${NEW_SOURCE}
done
#!/bin/bash
set -e
active_sink_file="/home/davide/.active-sink"
SINK1="alsa_output.pci-0000_01_00.1.hdmi-stereo-extra3"
SINK2="alsa_output.usb-Plantronics_Plantronics_C520_8F59C8CE5486C143BFE82700F5FEA1A1-00.analog-stereo"
ACTIVE_SINK=$(cat $active_sink_file)
echo $ACTIVE_SINK
if [ "$ACTIVE_SINK" == "$SINK1" ]
then
NEW_SINK=$SINK2
else
NEW_SINK=$SINK1
fi
echo $NEW_SINK > $active_sink_file
pacmd set-default-sink ${NEW_SINK}
pacmd list-sink-inputs | grep index | while read line
do
pacmd move-sink-input `echo $line | cut -f2 -d' '` ${NEW_SINK}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment