Shell mixer toggle script

I'm not aware of a way to toggle mixer on/off restoring your previous volume. So I just created a quick shell script to do it. Maybe someone will find it useful.


#!/bin/sh

VOL=$(mixer | awk -F ':' '/vol/{print $2}')

if [ $VOL -gt 0 ]; then
echo "${VOL}" > $HOME/.cache/mixervol
mixer vol 0 > /dev/null 2>&1
notify-send -i /usr/local/share/icons/gnome/32x32/status/audio-volume-muted.png "Volume Muted"
else
OVOL=$(cat $HOME/.cache/mixervol)
mixer vol ${OVOL} > /dev/null 2>&1
notify-send -i /usr/local/share/icons/gnome/32x32/status/audio-volume-medium.png "Volume Restored ${OVOL}"
fi
 
I'm not aware of a way to toggle mixer on/off restoring your previous volume. So I just created a quick shell script to do it. Maybe someone will find it useful.


#!/bin/sh

VOL=$(mixer | awk -F ':' '/vol/{print $2}')

if [ $VOL -gt 0 ]; then
echo "${VOL}" > $HOME/.cache/mixervol
mixer vol 0 > /dev/null 2>&1
notify-send -i /usr/local/share/icons/gnome/32x32/status/audio-volume-muted.png "Volume Muted"
else
OVOL=$(cat $HOME/.cache/mixervol)
mixer vol ${OVOL} > /dev/null 2>&1
notify-send -i /usr/local/share/icons/gnome/32x32/status/audio-volume-medium.png "Volume Restored ${OVOL}"

I think that mixer save you settings automatically(at least for me)
usefull script btw,thanks
I'm not aware of a way to toggle mixer on/off restoring your previous volume. So I just created a quick shell script to do it. Maybe someone will find it useful.


#!/bin/sh

VOL=$(mixer | awk -F ':' '/vol/{print $2}')

if [ $VOL -gt 0 ]; then
echo "${VOL}" > $HOME/.cache/mixervol
mixer vol 0 > /dev/null 2>&1
notify-send -i /usr/local/share/icons/gnome/32x32/status/audio-volume-muted.png "Volume Muted"
else
OVOL=$(cat $HOME/.cache/mixervol)
mixer vol ${OVOL} > /dev/null 2>&1
notify-send -i /usr/local/share/icons/gnome/32x32/status/audio-volume-medium.png "Volume Restored ${OVOL}"
fi

I think that mixer save you settings automatically(at least for me)
usefull script btw,thanks
 
I extended it to have a up/down command that steps through the volume by 5 each time. It also has a notify-send for each event. The step and DEV device are now configurable at the top of the script.

Bash:
#!/bin/sh

VOL=$(mixer | awk -F ':' '/vol/{print $2}') 
DEVICE="vol" #pcm
STEP="5"
CACHE="$HOME/.cache/mixervol"

if [ ! -e $CACHE ]; then
   echo "${VOL}" > $CACHE
fi

toggle () {
    if [ $VOL -gt 0 ]; then
        echo "${VOL}" > $CACHE
        mixer ${DEVICE} 0 > /dev/null 2>&1
        notify-send -i /usr/local/share/icons/gnome/32x32/status/audio-volume-muted.png "Volume Muted"
    else
        OVOL=$(cat $CACHE)
        mixer ${DEVICE} ${OVOL} > /dev/null 2>&1
        notify-send -i /usr/local/share/icons/gnome/32x32/status/audio-volume-medium.png "Volume Restored ${OVOL}"
    fi
}

volup () {
    mixer ${DEVICE} +${STEP}
    notify-send -t 850 -i /usr/local/share/icons/gnome/32x32/status/audio-volume-medium.png "Volume ${VOL}"
}

voldwn() {
    mixer ${DEVICE} -${STEP}
    notify-send -t 850 -i /usr/local/share/icons/gnome/32x32/status/audio-volume-low.png "Volume ${VOL}"
}

case ${1} in
    toggle)
        toggle
        ;;
    up )
        volup
        ;;
    down)
        voldwn
        ;;
    *)
        echo "Usage (toggle|up|down)"
        exit
esac
 
Last edited:
I have write something similar in my notebook, maped the volume up and down keys and wrote a script with xosd and mixer,I search for it....
 
Back
Top