Advertisement
addy-dclxvi

Untitled

Oct 19th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # finds the active sink for pulse audio and increments the volume. useful when you have multiple audio outputs and have a key bound to vol-up and down
  4.  
  5. osd='no'
  6. inc='2'
  7. capvol='no'
  8. maxvol='100'
  9. tmpfile='/tmp/pasink.tmp'
  10. autosync='yes'
  11.  
  12. active_sink=`pacmd list-sinks |awk '/* index:/{print $3}'`
  13. limit=$(expr 100 - ${inc})
  14. maxlimit=$(expr ${maxvol} - ${inc})
  15.  
  16. function volUp {
  17.  
  18. getCurVol
  19.  
  20. if [ ${capvol} = 'yes' ]
  21. then
  22. if [ ${curVol} -le 100 -a ${curVol} -ge ${limit} ]
  23. then
  24. pactl set-sink-volume ${active_sink} -- 100%
  25. elif [ ${curVol} -lt ${limit} ]
  26. then
  27. pactl set-sink-volume ${active_sink} -- +${inc}%
  28. fi
  29. elif [ ${curVol} -le ${maxvol} -a ${curVol} -ge ${maxlimit} ]
  30. then
  31. pactl set-sink-volume ${active_sink} ${maxvol}%
  32. elif [ ${curVol} -lt ${maxlimit} ]
  33. then
  34. pactl set-sink-volume ${active_sink} +${inc}%
  35. fi
  36.  
  37. getCurVol
  38.  
  39. if [ ${osd} = 'yes' ]
  40. then
  41. qdbus org.kde.kded /modules/kosd showVolume ${curVol} 0
  42. fi
  43.  
  44. if [ ${autosync} = 'yes' ]
  45. then
  46. volSync
  47. fi
  48. }
  49.  
  50. function volDown {
  51.  
  52. pactl set-sink-volume ${active_sink} -${inc}%
  53. getCurVol
  54.  
  55. if [ ${osd} = 'yes' ]
  56. then
  57. qdbus org.kde.kded /modules/kosd showVolume ${curVol} 0
  58. fi
  59.  
  60. if [ ${autosync} = 'yes' ]
  61. then
  62. volSync
  63. fi
  64.  
  65. }
  66.  
  67. function getSinkInputs {
  68.  
  69. inputs=`pacmd list-sink-inputs |grep -B 4 'sink: '${1}' ' |awk '/index:/{print $2}' >${tmpfile}`
  70. input_array=`cat $tmpfile`
  71. }
  72.  
  73. function volSync {
  74.  
  75. getSinkInputs ${active_sink}
  76. getCurVol
  77.  
  78. for each in ${input_array}
  79. do
  80. pactl set-sink-input-volume ${each} ${curVol}%
  81. done
  82.  
  83. }
  84.  
  85. function getCurVol {
  86.  
  87. curVol=`pacmd list-sinks |grep -A 15 'index: '${active_sink}'' |grep 'volume:' |egrep -v 'base volume:' |awk -F : '{print $3}' |grep -o -P '.{0,3}%'|sed s/.$// |tr -d ' '`
  88.  
  89. }
  90.  
  91. function volMute {
  92.  
  93. case "$1" in
  94. mute)
  95. pactl set-sink-mute ${active_sink} 1
  96. curVol=0
  97. status=1
  98. ;;
  99. unmute)
  100. pactl set-sink-mute ${active_sink} 0
  101. getCurVol
  102. status=0
  103. ;;
  104. esac
  105.  
  106. if [ ${osd} = 'yes' ]
  107. then
  108. qdbus org.kde.kded /modules/kosd showVolume ${curVol} ${status}
  109. fi
  110.  
  111. }
  112.  
  113. function volMuteStatus {
  114.  
  115. curStatus=`pacmd list-sinks |grep -A 15 'index: '${active_sink}'' |awk '/muted/{ print $2}'`
  116.  
  117. }
  118.  
  119.  
  120. case "$1" in
  121. --up)
  122. volUp
  123. notify-send "Volume Up " "$curVol%"
  124. ;;
  125. --down)
  126. volDown
  127. notify-send "Volume Down " "$curVol%"
  128. ;;
  129. --togmute)
  130. volMuteStatus
  131. if [ ${curStatus} = 'yes' ]
  132. then
  133. volMute unmute
  134. notify-send "Volume Unmute " "$curVol%"
  135. else
  136. volMute mute
  137. notify-send "Volume Mute " "$curVol%"
  138. fi
  139. ;;
  140. --mute)
  141. volMute mute
  142. notify-send "Volume Mute " "$curVol%"
  143. ;;
  144. --unmute)
  145. volMute unmute
  146. notify-send "Volume Unmute " "$curVol%"
  147. ;;
  148. --sync)
  149. volSync
  150. ;;
  151. *)
  152. getCurVol
  153. volMuteStatus
  154. if [ ${curStatus} = 'yes' ]
  155. then
  156. echo "  $curVol% "
  157. else
  158. echo "  $curVol% "
  159. fi
  160. ;;
  161. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement