Local

..:: Home
..:: Legal
..:: Contact
..:: About
..:: RSS
..:: Log in

Links

..:: Fake Bill Gates
..:: Tap the Hive

A Random Quote

"A foul's a foul, and a bat's a bat, even if it's flat. 10 feet on the Westside, is 10 feet on the Eastside. Football is football .... unless it's futbol. Now, a win's a win, and a loss is a loss. But no matter what, you'd better come with it, because it's 90 feet to first, no matter where home is."

Controlling PCM Volume in Linux Via Command Line

Some people want a script to control PCM volume via command line. The guys over at the Gentoo forums gave me something to start with and then I put the rest of this together. You can use this in conjunction with any key or voice listener daemon to control your volume, or just use it directly at the shell.

If you want to wget it, here’s the command to do so:

sudo wget http://www.djlosch.com/source/volmute -O /usr/bin/volmute

And, here’s the script itself:

#!/bin/bash
volsetting=`amixer sget 'PCM' | grep off`
    case "$1" in
    mute)
        amixer sset 'PCM' mute
    ;;
    unmute)
        amixer sset 'PCM' unmute
    ;;
    toggle)
        if [[ x"$volsetting" = x"" ]]; then
            amixer sset ‘PCM’ mute
        else
            amixer sset ‘PCM’ unmute
        fi
    ;;
    increase)
        amixer sset ‘PCM’ 8%+
    ;;
    decrease)
        amixer sset ‘PCM’ 8%-
    ;;
    *)
        echo “This is not an acceptable command!”;
        echo -e “Use \033[01;33mmute\033[01;00;0m, \033[01;33mincrease\033[01;00;0m or \033[01;33mdecrease\033[01;00;0m as options!”;
        echo;
    esac

Once the script is in your $PATH (/usr/bin is for example), here’s the usage:

volmute increase    #increase PCM volume
volmute decrease    #increase PCM volume
volmute mute        #mute PCM volume
volmute unmute      #unmute PCM volume
volmute toggle      #toggle muting of PCM volume

Note that you’ll need to use the toggle function if you’re mapping your keyboard’s mute button, although Ubuntu now has most keyboards’ multimedia keys working out of the box.

Leave a Reply