SHOW:
|
|
- or go back to the newest paste.
| 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 | 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%
|
| 24 | + | pactl set-sink-volume ${active_sink} 100%
|
| 25 | elif [ ${curVol} -lt ${limit} ]
| |
| 26 | then | |
| 27 | - | pactl set-sink-volume ${active_sink} -- +${inc}%
|
| 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}%
|
| 31 | + | pactl set-sink-volume ${active_sink} ${maxvol}%
|
| 32 | elif [ ${curVol} -lt ${maxlimit} ]
| |
| 33 | then | |
| 34 | - | pactl set-sink-volume ${active_sink} -- +${inc}%
|
| 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}%
|
| 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 | if [ ${curStatus} = 'yes' ]
| |
| 118 | then | |
| 119 | volMute unmute | |
| 120 | else | |
| 121 | volMute mute | |
| 122 | fi | |
| 123 | ||
| 124 | } | |
| 125 | ||
| 126 | ||
| 127 | case "$1" in | |
| 128 | --up) | |
| 129 | volUp | |
| 130 | ;; | |
| 131 | --down) | |
| 132 | volDown | |
| 133 | ;; | |
| 134 | --togmute) | |
| 135 | volMuteStatus | |
| 136 | ;; | |
| 137 | --mute) | |
| 138 | volMute mute | |
| 139 | ;; | |
| 140 | --unmute) | |
| 141 | volMute unmute | |
| 142 | ;; | |
| 143 | --sync) | |
| 144 | volSync | |
| 145 | ;; | |
| 146 | esac |