/Main_Page

::You must have ninja focus to complete your mission::NinjaFocus::

ALSA Volume Scripts

Views:


I needed to make the function keys on my Samsung N130 work under linux. All the information I needed was on the ArchLinux Samsung N140 page. I just needed to create a couple of scripts to control the volume, for xbindkeys to call.

/usr/local/bin/volume:

#!/bin/bash
# A basic script to control alsa mixer volume
# Copyright Kieran Whitbread 2010
VOLUME[0]=0
VOLUME[1]=6
VOLUME[2]=13
VOLUME[3]=18
VOLUME[4]=24
VOLUME[5]=33
VOLUME[6]=38
VOLUME[7]=45
VOLUME[8]=51
VOLUME[9]=57
VOLUME[10]=64

function help() {
    echo "$(basename $0) [0-10] | [up] | [down]"
}
function setVol() {
    amixer cset numid=11 $1 2&>1 > /dev/null
}
current=$(amixer cget numid=11 | head -3 | tail -1 | cut -d\= -f 2)
i=0
for VOL in ${VOLUME[@]}
do
    if [ $current -le $VOL ]
    then
        if [ $(( $VOL - $current )) -le 3 ]
        then
            current_index=$i
        else
            current_index=$(( $i + 1 ))
        fi
        break
    fi
    i=$(( $i + 1 ))
done

case $1 in
    up)
        if [ $current_index -lt 10 ]
        then
            setVol ${VOLUME[$(( $current_index + 1 ))]}
        fi    
        ;;
    down)
        if [ $current_index -gt 0 ]
        then
            setVol ${VOLUME[$(( $current_index - 1 ))]}
        fi
        ;;
    0|1|2|3|4|5|6|7|8|9|10)
        setVol ${VOLUME[$1]};;
    *)
        help;;
esac

/usr/local/bin/toggle-mute:

#!/bin/bash

MUTE=$(/usr/bin/amixer cget numid=12 | tail -1 | cut -d\= -f 2)
if [ "$MUTE" = on ]
then
    MUTE=off
else
    MUTE=on
fi
/usr/bin/amixer cset numid=12 $MUTE 2&>1 > /dev/null

Main Menu

Personal tools

Toolbox