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