Pulse audio increase decrease toggle volume from shell console

From Urandom
Jump to: navigation, search
* This script is based on the script found here http://crunchbanglinux.org/forums/topic/11392/pulseaudio-volume-control-with-media-keys/
* I made it take the current volume directly from pacmd dump.
* Also added a toggle functionality and it automatically unmutes when increasing volume with a muted sink.
* Changes all sinks at once
* Edit a file /usr/bin/pavolume.sh 
doit()
{

CURVOL=$((`pacmd dump | grep "set-sink-volume" | grep $DEV | cut -d " " -f 3`))
MUTE=`pacmd dump | grep "set-sink-mute" | grep $DEV | cut -d " " -f 3`
if [[ $ACTION == "toggle" ]]
then
        if [[ $MUTE == "yes" ]]
        then
                ACTION="unmute"
        else
                ACTION="mute"
        fi
elif [[ $ACTION == "increase" ]]
then
        if [[ $MUTE == "yes" ]]
        then
                ACTION="unmute"
        else
                CURVOL=$(($CURVOL + 3277))
        fi
elif [[ $ACTION == "decrease" ]]
then
        CURVOL=$(($CURVOL - 3277))
fi
echo $CURVOL $DEV
if [[ $CURVOL -le 65540 && $CURVOL -ge 0 ]] # Check to see if the volume is a valid number (65540 was needed in this case because of how I rounded the increment)
then
        pactl set-sink-volume $DEV $CURVOL
fi

if [[ $ACTION == "mute" ]]
then
        pactl set-sink-mute $DEV 1
elif [[ $ACTION == "unmute" ]]
then
        pactl set-sink-mute $DEV 0
fi
}

ACTION=$1
ALLDEV=`pacmd dump | grep "set-sink-mute" | cut -d " " -f 2`
for DEV in $ALLDEV
do
doit
done
* Don't forget to chmod +x!