diff --git a/togglehdmiaudio.sh b/togglehdmiaudio.sh new file mode 100755 index 0000000..848e2d1 --- /dev/null +++ b/togglehdmiaudio.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Toggle between HDMI and Analog +# Find out current RUNNING sink +currentSink=$(pactl list short sinks | grep 'RUNNING' | awk '{print$2}') +sink=NULL + +# Then find the first hdmi or analog sink +if [[ $currentSink == *"hdmi"* ]]; then + sink=$(pactl list short sinks | awk '{print$2}' | grep 'analog' | sed -n '1p') +else + sink=$(pactl list short sinks | awk '{print$2}' | grep 'hdmi' | sed -n '1p') +fi + +# Exit if there is no sink :( +if [ -z $sink ]; then + echo "Error! Could not find sink to toggle to!" + exit -1 +fi + +# Set outputs +echo "setting default sink to $sink" +pactl set-default-sink "$sink" +pactl list short sink-inputs|while read stream; do + streamId=$(echo $stream|cut '-d ' -f1) + echo "moving stream $streamId" + pactl move-sink-input "$streamId" "$sink" +done +