1#!/bin/bash
23
declare -i sinks_count=`pacmd list-sinks | grep -c index:[[:space:]][[:digit:]]`
45
if [ $sinks_count -eq 0 ] ; then
6exit
7fi
89
declare -i active_sink_index=`pacmd list-sinks | sed -n -e 's/\*[[:space:]]index:[[:space:]]\([[:digit:]]\)/\1/p'`
1011
active_index_position_found=0
12let next_sink_index=-1
13while read index ;
14do
15declare -i ind=($(echo $index | tr -dc '[0-9]+'))
16if [ $next_sink_index -lt 0 ] ; then
17export next_sink_index=$ind
18fi
19if [ $active_index_position_found -eq 1 ] ; then
20export next_sink_index=$ind
21break;
22fi
23if [ $active_sink_index -eq $ind ] ; then
24export active_index_position_found=1
25fi
26done < <(pacmd list-sinks | grep index:[[:space:]][[:digit:]])
2728
#change the default sink
29pacmd "set-default-sink ${next_sink_index}"
3031
#move all inputs to the new sink
32for app in $(pacmd list-sink-inputs | sed -n -e 's/index:[[:space:]]\([[:digit:]] \)/\1/p');
33do
34pacmd "move-sink-input $app $next_sink_index"
35done
3637
#display notification
38declare -i ndx=0
39pacmd list-sinks | sed -n -e 's/device.description[[:space:]]=[[:space:]]"\(.*\)"/\1/p' | while read line;
40do
41if [ $next_sink_index -eq $ndx ] ; then
42#notify-send -i notification-audio-volume-high "Sound output switched to" "$line"
43notify-send "Sound output switched" "$line"
44exit
45fi
46ndx+=1
47done;