Linux: Change volume using multimedia keys

ScreenshotI was looking for a way to change the volume using the multimedia keys on my keyboard. There are quite a few programms that should do the job, but all of them where running as a daemon (background process). In my opinion this is unneccesary because I need to raise/lower/mute the volume only once in a while. Therefore I wrote a quick’n'dirty bash script using ALSA’s amixer and the osd_cat utility.

Features

  • Raise/Lower Volume
  • Mute/Unmute
  • Displays the current volume on-screen using osd_cat

Usage

Open the script file with your favourite editor edit following to lines to fit your needs:

CONTROL="Front" CHANNEL="Front Left"

CONTROL is used to set the volume and CHANNEL to get the current volume. Run amixer to see which is the right control and amixer get YOUR-CONTROL to select one channel listed there.

Compiz Settings - General - ActionsAs I am using the compiz-fusion window manager along with the XFCE desktop I decided to use the built-in functions of compiz to bind the keys.


Compiz Settings - General - ActionsIn the CompizConfig Settings Manager select the General Options sub-dialog. Inside the Commands tab find three empty slots and bind them to:

PATH-TO-THE-SCRIPT/avolctrl.sh down PATH-TO-THE-SCRIPT/avolctrl.sh up PATH-TO-THE-SCRIPT/avolctrl.sh toggle

Finally bind those command slots to your multimedia keys. For me these were:

XF86AudioLowerVolume XF86AudioRaiseVolume XF86AudioMute

Prerequisites

For a different Linux distribution you need to find the appropriate packages your self or compile the binaries from the source code.

Download

Troubleshooting

In case the keys don’t work, check if your keyboard sends events to the xserver using xev. Additionally you might have to define the keys properly using xmodmap if it does not work out-of-the-box. Following codes are working for me (Microsoft Comfort Curve Keyboard)

keycode 160 = XF86AudioMute keycode 174 = XF86AudioLowerVolume keycode 176 = XF86AudioRaiseVolume

Known Bugs

  • No bugs known yet. As I said, very quick’n'dirty hack but should work anyway.

Tags: , ,

Leave a Reply

You must be logged in to post a comment.