Local

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

Links

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

A Random Quote

"Here's to the crazy ones. The misfits. The rebels. The trouble-makers. The round heads in the square holes. The ones who see things differently. They're not fond of rules, and they have no respect for the status-quo. You can quote them, disagree with them, glorify, or vilify them. But the only thing you can't do is ignore them. Because they change things. They push the human race forward. And while some may see them as the crazy ones, we see genius. Because the people who are crazy enough to think they can change the world, are the ones who do." -- Jack Kerouac

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