libaosd Method is much prettier than the XOSD Method
libaosd Method[]
Requirements[]
Usage[]
all the following displays volume
- Increase volume
- aosd_volume volup
- Decrease volume
- aosd_volume voldown
- Mute volume
- aosd_volume mute
Script[]
name the script, aosd_volume
#!/bin/bash # Detect mute status and set OSD color MUTESTATUS=$(amixer get $MIXERNAME | grep "Left:" | awk '{print $4}' | tr -d '[]') if [ $MUTESTATUS == "off" ]; then OSDCOLOR=red; else OSDCOLOR=green fi # Create the "I" bar based on mixer setting and granularity volset=$(amixer get $MIXERNAME | grep "Left:" | awk '{print $4}') let volcounter=volset/$VOLINC if [ $volcounter -gt $GRANULARITY ]; then volcounter=$GRANULARITY fi OSDI="" while [ $volcounter -gt 0 ] do OSDI=`echo $OSDI"I"` let volcounter=volcounter-1 done # Clean up any running aosd_cat processes killall aosd_cat &> /dev/null # Display the "I" bar echo "$OSDI" | aosd_cat -n "Arial Black $FONTSIZE" -u 1000 -o 200 -R $OSDCOLOR -S none -f 0 -y -10 # END
XOSD Method[]
Requirements[]
- XOSD
- Large Bitmap font
- Example: 10x20 (download)
Usage[]
all the following displays volume
- Display volume
- xosd_volume show
- Increase volume
- xosd_volume incr
- Decrease volume
- xosd_volume decr
- Mute volume
- xosd_volume mute on/off
Script[]
Name the script xosd_volume
#!/bin/bash ##################### # Config CHANNEL='PCM' FONT='10x20' #################### # Code action=$1; shift # Unmute the volume and increase/decrease it # Arg 1: volume change to set (1+ or 1-) set_volume() { amixer sset $CHANNEL unmute &> /dev/null & volume=$(amixer sset $CHANNEL $1 unmute | \ grep "Left: Playback" | \ grep -o "\[[0-9]*%\]" | \ tr '[%]' ' ') } # Get the current volume % # No args get_volume() { volume=$(amixer sget $CHANNEL | \ grep "Left: Playback" | \ grep -o "\[[0-9]*%\]" | \ tr '[%]' ' ') } # Toggle Master volume mute on/off # No args mute_volume() { status=$(amixer sset $CHANNEL toggle | \ grep "Left: Playback" | \ grep -o "\[on\]\|\[off\]" | \ tr '[]' ' ') } # Use xosd to show a volume guage on the screen # Arg 1: Current volume as percent of full volume # Arg 2: (optional) Text to show above bar show_volume() { killall -9 -q osd_cat &>/dev/null osd_cat --font="$FONT" --shadow=1 --color=green --pos=middle --align=center --delay=2 --text "$( [ "z$2" = "z" ] && echo Volume: $1% || echo $2 )" --barmode=percentage --percentage=$1 } case "$action" in show) get_volume show_volume $volume ;; incr) delta=1+ set_volume $delta show_volume $volume ;; decr) delta=1- set_volume $delta show_volume $volume ;; mute) mute_volume case "$status" in off) show_volume 0 "Muted" ;; on) get_volume show_volume $volume ;; esac ;; *) echo "Usage: $0 {incr|decr|mute|show}" ;; esac
External Links[]
- https://bbs.archlinux.org/viewtopic.php?id=41204 - original forum discussion where XOSD script is based on
- http://ubuntuforums.org/showthread.php?t=1174798 - another xosd bash script
- http://crunchbanglinux.org/forums/topic/4994/osd-for-openbox-using-aosdcat/ - a method using libaosd, for a better display, and more configurable fonts, code from this forum was used in the libaosd Method