scripts/togglehdmiaudio.sh

31 lines
868 B
Bash
Raw Normal View History

2019-03-13 21:02:37 +02:00
#!/bin/bash
# Toggle between HDMI and Analog
# Find out current RUNNING sink
currentSink=$(pactl list short sinks | grep 'RUNNING' | awk '{print$2}')
2019-05-18 13:05:19 +03:00
#currentSink=$(pactl info | grep "Default Sink:" | awk '{print$3}')
2019-03-13 21:02:37 +02:00
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