Skip to content

Instantly share code, notes, and snippets.

@loiclefloch
Created December 15, 2014 20:51
Show Gist options
  • Save loiclefloch/a433a46af12131318d68 to your computer and use it in GitHub Desktop.
Save loiclefloch/a433a46af12131318d68 to your computer and use it in GitHub Desktop.
Alsamixer with aosd_cat
#!/bin/bash
# By Loic Lefloch
# Many thanks to crunchbang community and other contributors
#================================================================================
# Some user-defined values
MIXERNAME="Master" # The name of the amixer master device
GRANULARITY=32 # The approximate number of possible volume positions allowed
# aosd options
FONTSIZE=40 # The size of font used by the OSD display
VOLCOLOR=#ccc # Color for volume bar
MUTECOLOR=red # Color for mute notification
FONT="Arial Black"
# Pull the numerical limit from the Mixer
LIMIT=$(amixer get $MIXERNAME | grep "Limits" | awk '{print $5}')
# Set volume increment based on granularity
let VOLINC=LIMIT/GRANULARITY
let volmod=LIMIT%GRANULARITY
let threshold=GRANULARITY/2
if [ $volmod -gt $threshold ]; then
let VOLINC=VOLINC+1
fi
ACTION=""
case $1 in
volup) $(amixer set $MIXERNAME $VOLINC+% > /dev/null) && ACTION="+" ;;
voldown) $(amixer set $MIXERNAME $VOLINC-% > /dev/null) && ACTION="-" ;;
mute) $(amixer -D pulse -q sset $MIXERNAME toggle) && ACTION="M" ;; #(amixer -D pulse -q sset $MIXERNAME toggle amixer -D pulse set Master toggle
*)
echo "Usage: $0 { volup | voldown | mute }"
exit
;;
esac
MUTESTATUS=$(amixer get $MIXERNAME | grep "Mono:" | awk '{print $6}' | tr -d '[]')
if [ $MUTESTATUS == "off" ]; then
OSDCOLOR="$MUTECOLOR"
else
OSDCOLOR="$VOLCOLOR"
fi
volset=$(amixer get $MIXERNAME | grep "Mono:" | awk '{print $3}')
let volcounter=volset/$VOLINC
echo $volcounter;
echo $GRANULARITY;
if [ $volcounter -gt $GRANULARITY ]; then
volcounter=$GRANULARITY
fi
OSDI=""
rest=$(($GRANULARITY-$volcounter-1))
while [ $volcounter -gt 0 ]
do
OSDI=`echo $OSDI"I"`
let volcounter=volcounter-1
done
while [ $rest -gt 0 ]
do
OSDI=`echo $OSDI"-"`
let rest=rest-1
done
killall aosd_cat &> /dev/null
echo "$ACTION $OSDI" | aosd_cat -n "$FONT $FONTSIZE" -u 500 -o 300 -R $OSDCOLOR -S none -f 0 -y -10
# END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment