Volume Control OSD for Openbox
I’ve looked up a lightweight volume control OSD for Openbox for over an hour. I want it simple, no-dependency and XF86Audio-keys-supported so it’s really hard to find. But finally I got this pretty tool, written in Bash. It’s a small script which can be well integrated with Openbox’s keybind.
You may need libaosd to use this tool. You can install it by running:
yaourt libaosd
Here’s the tool (slightly modified by me):
#!/bin/bash
#============================================#
# mixer-osd
#============================================#
S="$(amixer set Master 0+ | grep 'Mono:' | awk '{print $6}' | tr -d '[]')"
case $1 in
volup)
case $S in
on) A="VOLUME: $(amixer set Master 1+ | grep 'Mono:' | awk '{print $4}' | tr -d '[]')" ;;
off) A="[MUTED] VOLUME: $(amixer set Master 1+ | grep 'Mono:' | awk '{print $4}' | tr -d '[]')" ;;
esac ;;
voldown)
case $S in
on) A="VOLUME: $(amixer set Master 1- | grep 'Mono:' | awk '{print $4}' | tr -d '[]')" ;;
off) A="[MUTED] VOLUME: $(amixer set Master 1- | grep 'Mono:' | awk '{print $4}' | tr -d '[]')" ;;
esac ;;
mute)
case $(amixer set Master toggle | grep 'Mono:' | awk '{print $6}' | tr -d '[]') in
on) A="VOLUME: $(amixer set Master 0+ | grep 'Mono:' | awk '{print $4}' | tr -d '[]')" ;;
off) A="[MUTED] VOLUME: $(amixer set Master 0+ | grep 'Mono:' | awk '{print $4}' | tr -d '[]')" ;;
esac ;;
*) echo "Usage: $0 { volup | voldown | mute }" ;;
esac
killall aosd_cat &> /dev/null
echo "$A" | aosd_cat -p 4 --fore-color=green --shadow-color=#006633 --font="Droid Sans Mono 16" --x-offset=-40 --y-offset=-0 --transparency=2 --fade-in=0 --fade-out=0 --fade-full=1000 &
# END
To use it, save the above script as /usr/bin/mixer-osd
, and add the following
configurations in your Openbox’s rc.xml
:
<!-- Keybindings for volume control -->
<keybind key="XF86AudioRaiseVolume">
<action name="Execute">
<execute>
mixer-osd volup
</execute>
</action>
</keybind>
<keybind key="XF86AudioLowerVolume">
<action name="Execute">
<execute>
mixer-osd voldown
</execute>
</action>
</keybind>
<keybind key="XF86AudioMute">
<action name="Execute">
<execute>
mixer-osd mute
</execute>
</action>
</keybind>
OK, you’re done. Try pressing the volume-down, volume-up and mute key on your, laptop, perhaps. There will be a green banner in the center of your display telling you the volume and whether it’s muted.
Acknowledgement. http://techpatterns.com/forums/about1354.html
Note. You can also directly use amixer to adjust volume as stated in this
article:
http://urukrama.wordpress.com/2007/12/19/managing-sound-volumes-in-openbox/.
However I think osdsh
is a little bit harder to configure than aosd_cat
.