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