#!/bin/bash ####################################### ## Graphical volume handler. ## Usage: vol [command|increment] ## OPTIONS: ## command One of 'down' or 'up' or 'mute' or 'maximize' ## increment Adjust master volume by/to argument (like -10 or +25) ## IF MUTED: vol will un-mute with any argument, ignoring the argument ## IF MAXIMIZED: vol will un-max with any argument, ignoring the argument ## NO OPTION: vol will show the current volume. does nothing when muted. ## vol 0.1, (c) 2003 by Adam Katz , consider the licence GPL ####################################### # basic structure and core commands taken from: # http://www.alobbs.com/modules.php?op=modload&name=News&file=article&sid=70 # as posted by Alvaro Lopez Orgega 1/2003 # re-written 11/2003 by Adam Katz # INSTALL NOTES: # this script requires osd_cat and aumix! # ideally, you want a symlink to osd_cat called vol_meter # you can set it up on a dell laptop with: # i8kbuttons -u 'vol up' -d 'vol dn' -m 'vol mute' # the following variables should be all you need for tweaking: # this script is NOT meant to be installed in /usr/bin or /usr/local/bin. # it is designed to be used by an individual that the vol_meter can be in ~/bin vol_meter=vol_meter # should be a symlink to osd_cat COLOR=green FONT="-adobe-courier-bold-r-normal-*-*-180-*-*-m-*-iso8859-1" X_OFFSET=10 # distance from left edge of screen Y_OFFSET=53 # distance from top edge of screen MUTED_FILE="/tmp/.vol_is_muted" VOL_FACTOR=4 # fractions of 100 to represent volume MAX_VOLUME=$((100/$VOL_FACTOR)) # don't change this, it's just math # take first of the following from the $PATH, except this file vol_meter=`which $vol_meter vol_meter osd_cat 2>/dev/null \ |grep -v "$0$" |head -n1` if [ -z "$vol_meter" ]; then echo "`basename $0`: You must have osd_cat (of xosd-bin) installed for this to work" exit 127 fi vol_level () { aumix -q | grep vol | cut -f2 -d" " | cut -f1 -d"," } get_vol () { vol=`vol_level` # if we are muted or maxed, report that and exit [ -s "$MUTED_FILE" ] && [ "$vol" = "0" ] && echo "MUTE" && exit 0 [ -s "$MUTED_FILE" ] && [ "$vol" = "100" ] && echo "MAX VOL" && exit 0 line=" Vol: ${vol}% " vol=$(($vol/$VOL_FACTOR)) for i in `seq $vol`; do line="$line|" done let rest=`expr $MAX_VOLUME - $vol` for i in `seq $rest`; do line="$line-" done echo "$line" } draw_line () { [ -s "$MUTED_FILE" ] && DELAY=40000000 || DELAY=2 # display for 1yr or 2sec killall -9 -q $vol_meter >/dev/null get_vol |$vol_meter -p top -A left -l1 -d$DELAY \ -i$X_OFFSET -o$Y_OFFSET \ -s1 -c "$COLOR" -f "$FONT" >/dev/null 2>&1 & } less_vol () { aumix -v -5 -w -5 } more_vol () { aumix -v +5 -w +5 } mute_vol () { if [ -s "$MUTED_FILE" ] then # un-mute aumix -f "$MUTED_FILE" -L >/dev/null # restore settings rm -f "$MUTED_FILE" # caveat: if volume is modified elsewhere, we discard that blindly. else # mute aumix -f "$MUTED_FILE" -S # back up settings aumix -v0 -w0 -p0 -l0 -m0 -c0 -10 >/dev/null fi } max_vol () { if [ -s "$MUTED_FILE" ] then # un-max aumix -f "$MUTED_FILE" -L >/dev/null # restore settings rm -f "$MUTED_FILE" # caveat: if volume is modified elsewhere, we discard that blindly. else # maximize (just master and wavetable) aumix -f "$MUTED_FILE" -S # back up settings aumix -v100 -w100 >/dev/null fi } ####### # main ####### if `echo " $@" |grep -E ' --help| help' >/dev/null` then grep '^## ' `which $0 2>/dev/null || echo $0` |sed 's/^...//' fi if [ -s "$MUTED_FILE" ] then [ $# -gt 0 ] && mute_vol # if an action is specified, unset mute/maximize else case "$1" in # switch on what the action was down | dn | less | - ) less_vol ;; up | more | + ) more_vol ;; mute | off | toggle ) mute_vol ;; max* | peak | full | all ) max_vol ;; '' ) ;; # no action: do nothing but display the volume * ) aumix -v $@ ;; # adjust the main volume by/to argument (eg -10) esac fi draw_line