Advertisement
theroot

pavolume.sh

Apr 4th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/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='yes'
  6. inc=5
  7. capvol='yes'
  8. maxvol='200'
  9.  
  10. active_sink=`pacmd list-sinks |awk '/* index:/{print $3}'`
  11. limit=$(expr 100 - ${inc})
  12. maxlimit=$(expr ${maxvol} - ${inc})
  13.  
  14. function volUp {
  15.  
  16.         preVol=`pacmd list-sinks |grep -A 15 'index: '${active_sink}'' |awk '/volume: 0:/{ print $3}'|sed s/.$//`
  17.  
  18.         if [ ${capvol} = 'yes' ]
  19.         then
  20.                 if [ ${preVol} -le 100 -a ${preVol} -ge ${limit} ]
  21.                 then
  22.                         pactl set-sink-volume ${active_sink} -- 100%
  23.                 elif [ ${preVol} -lt ${limit} ]
  24.                 then
  25.                         pactl set-sink-volume ${active_sink} -- +${inc}%
  26.                 fi
  27.         elif [ ${preVol} -le ${maxvol} -a ${preVol} -ge ${maxlimit} ]
  28.         then
  29.                 pactl set-sink-volume ${active_sink} -- ${maxvol}%
  30.         elif [ ${preVol} -lt ${maxlimit} ]
  31.         then
  32.                 pactl set-sink-volume ${active_sink} -- +${inc}%
  33.         fi
  34.  
  35.         curVol=`pacmd list-sinks |grep -A 15 'index: '${active_sink}'' |awk '/volume: 0:/{ print $3}'|sed s/.$//`
  36.  
  37.         if [ ${osd} = 'yes' ]
  38.         then
  39.                 qdbus org.kde.kded /modules/kosd showVolume ${curVol} 0
  40.         fi
  41.  
  42. }
  43.  
  44. function volDown {
  45.  
  46.         pactl set-sink-volume ${active_sink} -- -${inc}%
  47.         curVol=`pacmd list-sinks |grep -A 15 'index: '${active_sink}'' |awk '/volume: 0:/{ print $3}'|sed s/.$//`
  48.         if [ ${osd} = 'yes' ]
  49.         then
  50.                 qdbus org.kde.kded /modules/kosd showVolume ${curVol} 0
  51.         fi
  52.  
  53. }
  54.  
  55. function volMute {
  56.  
  57.         case "$1" in
  58.                 mute)
  59.                         pactl set-sink-mute ${active_sink} 1
  60.                         curVol=0
  61.                         status=1
  62.                 ;;
  63.                 unmute)
  64.                         pactl set-sink-mute ${active_sink} 0
  65.                         curVol=`pacmd list-sinks |grep -A 15 'index: '${active_sink}'' |awk '/volume: 0:/{ print $3}'|sed s/.$//`
  66.                         status=0
  67.                 ;;
  68.         esac
  69.  
  70.         if [ ${osd} = 'yes' ]
  71.         then
  72.                 qdbus org.kde.kded /modules/kosd showVolume ${curVol} ${status}
  73.         fi
  74.  
  75. }
  76.  
  77. function volMuteStatus {
  78.  
  79.         curStatus=`pacmd list-sinks |grep -A 15 'index: '${active_sink}'' |awk '/muted/{ print $2}'`
  80.  
  81.         if [ ${curStatus} = 'yes' ]
  82.         then
  83.                 volMute unmute
  84.         else
  85.                 volMute mute
  86.         fi
  87.  
  88. }
  89.  
  90. case "$1" in
  91.         --up)
  92.                 volUp
  93.         ;;
  94.         --down)
  95.                 volDown
  96.         ;;
  97.         --togmute)
  98.                 volMuteStatus
  99.         ;;
  100.         --mute)
  101.                 volMute mute
  102.         ;;
  103.         --unmute)
  104.                 volMute unmute
  105.         ;;
  106. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement