#!/usr/bin/perl # Nasty little hack for keyboard based volume/mute controls with OSD display # Requires: xosd(osd_cat), alsa(amixer) # # Execute via keybindings in windowmanager # See: http://linux.oneandoneis2.org/keys.htm # # -MadCamel 2007 $arg = shift; $param = "1+%" if ($arg =~ /up/); $param = "1-%" if ($arg =~ /down/); if ($arg =~ /mute/) { system("amixer set Master toggle"); if (ismuted()) { $mute = "ON"; $color = "red"; } else { $mute = "OFF"; $color = "blue"; } system("killall osd_cat >/dev/null 2>&1"); system("echo Mute: $mute |osd_cat -p bottom -A center -c $color -f '-*-*-*-*-*-*-24-*-*-*-*-*-*-*' -d 1 &"); exit; } open(AMIX, "amixer set Master $param |") or die("amixer: $!\n"); while() { if (/\[(\d+)\%\]/) { $percent = $1; last; } } if (ismuted()) { $color = "red"; } else { $color = "blue"; } system("killall osd_cat >/dev/null 2>&1"); system("osd_cat -p bottom -A center -c $color -b percentage -f '-*-*-*-*-*-*-24-*-*-*-*-*-*-*' -P $percent -d 1 &"); sub ismuted { my $muted; open(AMIX, "amixer get Master |") or die("amixer: $!\n"); while() { $muted = 1 if (/\[off\]/); } return($muted); }