I was missing my volume buttons on my thinkpad, I’m sure the default flavours of (XU|KU|U)buntu handle this nicely (can’t say I checked though ;). But since I run ion3 I get none of that fluffyness.
There are ofcourse already some onelines and scripts outthere that fix this problem, and I certainly copied from them what was useful, but I wanted my OSD feedback. So I wrote the following script, not fancy but it works.
It depends on the following packages:
- perl
- alsa-utils
- xosd-bin
/usr/local/bin/ibmvolume.pl
#!/usr/bin/perl -w
use strict;
## Script made for Lenovo Thinkpad X61s
## for different cards you might need a different numid.
my $nvol = '28';
my $nmute = '29';
my $volinfo = `amixer cget numid=28`;
my $muteinfo = `amixer cget numid=29`;
my ($min, $max, $cur) =
$volinfo =~ /.*min=(.+?),.*max=(.+?),.*values=([0-9]+).*/si;
my $per = int($cur / ($max / 100));
my ($mute) = $muteinfo =~ /.*values=([a-z]+).*/si;
my $invmute = ($mute eq 'on') ? 'off' : 'on';
if($#ARGV < 0) {
print "Min: $min, Max: $max, Cur: $cur($per%), Mute: $mute($invmute)\n";
print "Usage: $0 (up|down|mute|show)\n";
exit 1;
}
my $command = shift;
my %controls = (
up => "amixer -q cset numid=$nvol ".($cur+1),
down => "amixer -q cset numid=$nvol ".($cur-1),
mute => "amixer -q cset numid=$nmute $invmute",
);
system($controls{$command}) if $controls{$command};
my $cmute = ($command eq 'mute') ? $invmute : $mute;
my $font = '*-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1';
system("osd_cat -b percentage -f $font -c green -A center -o 600 -d 1 -T 'Volume($cmute):' -P $per &");
Sadly the osd_cat tool can wait no shorter than 1 second, I would’ve liked something more like 0.5 second.
This now works from the commandline, taking commands like ‘up’, ‘down’, ‘mute’ and ‘show’. Now one can use something like ‘xbindkeys’ to link it to key events like ‘XF86AudioRaiseVolume’ and ‘XF86AudioLowerVolume’.
But I just put the following code in my (lua) config for ion3:
~/.ion3/cfg_bindings.lua
defbindings("WMPlex.toplevel", {
kpress("XF86AudioRaiseVolume", "ioncore.exec_on(_, '/usr/local/bin/ibmvolume.pl up')"),
kpress("XF86AudioLowerVolume", "ioncore.exec_on(_, '/usr/local/bin/ibmvolume.pl down')"),
kpress("XF86AudioMute", "ioncore.exec_on(_, '/usr/local/bin/ibmvolume.pl mute')"),
})
And don’t forget to reload ion3 afterwards :)

