Advertisement
theroot

pavolume.sh

Feb 7th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.10 KB | None | 0 0
  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. active_sink=`pacmd list-sinks |awk '/* index:/{print $3}'`
  6. osd='yes'
  7. inc=5
  8.  
  9. function volUp {
  10.  
  11.         pactl set-sink-volume ${active_sink} -- +${inc}%
  12.         curVol=`pacmd list-sinks |grep -A 15 'index: '${active_sink}'' |awk '/volume: 0:/{ print $3}'|sed s/.$//`
  13.         if [ ${osd} = 'yes' ]
  14.         then
  15.                 qdbus org.kde.kded /modules/kosd showVolume ${curVol} 0
  16.         fi
  17.  
  18. }
  19.  
  20. function volDown {
  21.  
  22.         pactl set-sink-volume ${active_sink} -- -${inc}%
  23.         curVol=`pacmd list-sinks |grep -A 15 'index: '${active_sink}'' |awk '/volume: 0:/{ print $3}'|sed s/.$//`
  24.         if [ ${osd} = 'yes' ]
  25.         then
  26.                 qdbus org.kde.kded /modules/kosd showVolume ${curVol} 0
  27.         fi
  28.  
  29. }
  30.  
  31. function volMute {
  32.  
  33.         case "$1" in
  34.                 mute)
  35.                         pactl set-sink-mute ${active_sink} 1
  36.                         curVol=0
  37.                         status=1
  38.                 ;;
  39.                 unmute)
  40.                         pactl set-sink-mute ${active_sink} 0
  41.                         curVol=`pacmd list-sinks |grep -A 15 'index: '${active_sink}'' |awk '/volume: 0:/{ print $3}'|sed s/.$//`
  42.                         status=0
  43.                 ;;
  44.         esac
  45.  
  46.         if [ ${osd} = 'yes' ]
  47.         then
  48.                 qdbus org.kde.kded /modules/kosd showVolume ${curVol} ${status}
  49.         fi
  50.  
  51. }
  52.  
  53. function volMuteStatus {
  54.  
  55.         curStatus=`pacmd list-sinks |grep -A 15 'index: '${active_sink}'' |awk '/muted/{ print $2}'`
  56.  
  57.         if [ ${curStatus} = 'yes' ]
  58.         then
  59.                 volMute unmute
  60.         else
  61.                 volMute mute
  62.         fi
  63.  
  64. }
  65.  
  66. case "$1" in
  67.         --up)
  68.                 volUp
  69.         ;;
  70.         --down)
  71.                 volDown
  72.         ;;
  73.         --togmute)
  74.                 volMuteStatus
  75.         ;;
  76.         --mute)
  77.                 volMute mute
  78.         ;;
  79.         --unmute)
  80.                 volMute unmute
  81.         ;;
  82. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement