Adjust volume via commandline so that volume notify pops up

Install the xdotool package, and try issuing

xdotool key XF86AudioLowerVolume

and

xdotool key XF86AudioRaiseVolume

You could bind a shortcut to this script I've found in the Arch forums (needs the package libnotify-bin):

#!/bin/sh

usage="usage: $0 -c {up|down|mute} [-i increment] [-m mixer]"
command=
increment=5%
mixer=Master

while getopts i:m:h o
do case "$o" in
    i) increment=$OPTARG;;
    m) mixer=$OPTARG;;
    h) echo "$usage"; exit 0;;
    ?) echo "$usage"; exit 0;;
esac
done

shift $(($OPTIND - 1))
command=$1

if [ "$command" = "" ]; then
    echo "usage: $0 {up|down|mute} [increment]"
    exit 0;
fi

display_volume=0

if [ "$command" = "up" ]; then
    display_volume=$(amixer set $mixer $increment+ unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1)
fi

if [ "$command" = "down" ]; then
    display_volume=$(amixer set $mixer $increment- unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1)
fi

icon_name=""

if [ "$command" = "mute" ]; then
    if amixer get Master | grep "\[on\]"; then
        display_volume=0
        icon_name="notification-audio-volume-muted"
        amixer set $mixer mute
    else
        display_volume=$(amixer set $mixer unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1)
    fi
fi

if [ "$icon_name" = "" ]; then
    if [ "$display_volume" = "0" ]; then
        icon_name="notification-audio-volume-off"
    elif [ "$display_volume" -lt "33" ]; then
        icon_name="notification-audio-volume-low"
    elif [ "$display_volume" -lt "67" ]; then
        icon_name="notification-audio-volume-medium"
    else
        icon_name="notification-audio-volume-high"
    fi
fi
notify-send " " -i $icon_name -h int:value:$display_volume -h string:synchronous:volume

Seems to work fine in Ubuntu 10.10.


Control Sound Volume

You can use amixer to control the sound volume, e.g.

amixer set 'Master' 50%
amixer set 'Master' 10%+
amixer set 'Master' 2dB-

You may need to set the soundcard using e.g. -c 1 for the second soundcard, see man amixer.

Play Sound

Sounds can be played using a player like aplay or paplay, e.g.

paplay /usr/share/sounds/freedesktop/stereo/audio-volume-change.oga

You might want to have a look at this question: Where do I find system sounds?

Display On-Screen Notification

You can reproduce the on-screen notification using the X On-Screen Display library XOSD. The package is called xosd-bin and the command osd_cat is used to display text, status bars etc. on the screen.

osd_cat -b percentage -P 20 -T Status: -f "-adobe-helvetica-bold-*-*--34-*-*-*-*"

displays

enter image description here

See this German wiki page for options and examples and man osd_cat for more.