Changing sound volumes in Openbox

December 19, 2007

You can use several applications to adjust the volume. Try alsamixer, a command-line mixer for alsa which comes with ubuntu (part of alsa-utils), or one of the many frontends for it: alsamixergui; qamix, a Qt front-end for alsamixer; gamix, a Gtk front-end; or (if you can tolerate gnome dependencies) gnome-alsamixer. You can also use xfce4-mixer, though it loads xfce-mcs-manager which might interfere with your gtk settings if you use another method to apply these. You can use all of these to control the volume, 3D switches, the volume of CD audio, line-in, headphones, phone, etc.

There are also several dockapps available to adjust the volume. Have a look here.

Several panels also have plugins to adjust the volume: this is the case for the lxpanel, perlpanel, xfce4-panel (using xfce4-mixer), gnome-panel, and kicker.

While all these applications may be useful, it is generally easier to change the volume by pressing a single key or a combination of keys on your keyboard. How can you accomplish this in Openbox?

The following commands turn the volume up and down:

    Up: amixer -q set PCM 1+ unmute

    Down: amixer -q set PCM 1- unmute

To toggle mute, use the following command:

    amixer -q set PCM toggle

If you’d rather change the master volume (as opposed to the PCM), use the following commands:

    Up: amixer -q set Master 1+ unmute

    Down: amixer -q set Master 1- unmute

    Mute: amixer -q set Master toggle

To make these commands more convenient, assign keyboard bindings to them in the rc.xml file. I use Ctrl+Up, Ctrl+Down, and Ctrl+Alt+End to turn the volume up, down and on/off. If you are more of a mouse person, you could also use a dockapp with launchers and assing the above commands to some launchers.

If you like an on-screen display when you change the volume, you can use OSDsh, a small application that shows the volume levels of your soundcard whenever they change. It is in the Ubuntu repositories.

In order to use OSDsh, you have to run it in the background. Install the application (duh!), and add the following lines to your autostart file (~/.config/openbox/autostart.sh):

	osdsh &
	(sleep 1 && osdctl -m 1) &

You can use themes to adjust the looks of OSDsh. To create your own themes, use the command “osdshconfig“. Themes allow you to change the colours, position, fonts, shadow offset, outline width and the delay of the on-screen-display. To apply them, use the following command in your autostart file, after “osdsh &”:

	osdctl -S /path/to/your/theme/file

15 Responses to “Changing sound volumes in Openbox”

  1. Peter said

    I could not help noticing that while you linked a page showing some dockapps you make no mention of system tray applications (other than those that come as panel plugins) – gvtray is worth a look and for those like me that find gvtray’s icon annoying then David Chalkskeletons modified gvtray code is easy to install.

    gvtray
    http://code.google.com/p/gtk-tray-utils/

    David Chalkskeletons modified gvtray
    http://david.chalkskeletons.com/blog/?p=20

  2. Timóteo said

    Hey man thks a lot

    Your blog help me a lot configuring my Openbox ^^
    I’m using osdsh to control the volume, but i dont get why when it starts the text appear really big o.o

    It’s very ugly =\

    Do you know if there is another program to do that?
    I’ll keep looking in google.

    Thks again.

  3. urukrama said

    Thank you.

    As I mentioned, you can use themes with osdsh. I’ve upload one I’ve used here (notice the font strings in that file). At the very end of this blog post I mentioned how to load themes.

    You can create new themes either by modifying this file or by using osdshconfig (comes with osdsh).

  4. […] Fortunately, urukrama came to the rescue. Not only had he just posted his rc.xml for Openbox, but he has an entire page devoted to setting up volume keys in Openbox. […]

  5. ikaruga said

    I’m a first time reader — wow this blog just keeps getting better! Where have you been on the openbox chatrooms? I asked them once for an OSD program and they told me to download the OSD *library* — library not *program* — I would have had to write custom C programs for everything I did 😦 This is much better — thanks for the tip.

  6. zelrik said

    hmm I tried it. It doesnt work. The command osdsh do nothing

  7. Brian said

    I’m using cruncheee and the command osdctl -m 1 in the terminal gives me:

    Error opening: No such file or directory
    /dev/mixer: Illegal seek

    and there is no mixer display

  8. asm0 said

    I’ve tried using your key binding configuration (C-Up, C-Down, etc.) and I’ve also tried mapping it to the keycodes for my particular keyboard volume controls (I use Fn+End for mute, Fn+PageDn for vol down and Fn+PageUp for vol up… which are keycodes 121, 122, and 123 respectively)… neither one worked. The only thing that I changed from the original code insert was adding my keycodes, so apparently, the only way that I can turn the volume up or down on my system would be by clicking on the speaker icon in crunchbang’s system tray (I’m using 9.04, so it’s Tint2 panel for me). Unless I’m missing something… I dunno.

  9. the dsc said

    For those who use fbpanel, but perhaps other panels as well, I recommend volwheel.

    I’d still prefer that we could program the openbox window title bar somewhat more freely, a bit like we program the fbpanel. So we could just place an arbitrary icon there, and program it to lower or raise the volume with the mousewheel.

    It really bugs me, the fact that no *box has yet made the auxiliary panels totally superflous through a more flexible configuration of the titlebar. I think it would still be good to have an optional real toolbar like fluxbox has, though, just in case — and perhaps making the change easier for those who may want to try it, coming from a more windowsesque desktop environment.

  10. […] [1] Chaning sound volumes in openbox 留下迴響 […]

  11. Shark said

    Great weblog. You really did a job

    I installed Openbox and i am really impressed but i have one big problem. When i move window the edges of it are slow and looks like they “disintegrate” – i assume refresh rate problem or something.

    So, how can i fix the problem?

    My comp specs:
    ASUS k50ij
    DuoT3000
    2gb RAM
    320 gb HDD
    INTEL GMA 4500M

    thx

  12. vinylplz said

    urukrama,

    Thanks for the tips. I was able to configure volume control using the windoze key and mouse wheel in fluxbox to my liking by simply adding these two lines to my ~/.fluxbox/keys file:

    Mod4 Mouse4 :Exec amixer -q set Master 10+ unmute
    Mod4 Mouse5 :Exec amixer -q set Master 10- unmute

    Exactly what I wanted. Thanks.

  13. sosek said

    urukrama,
    Can you help me with preparing similar script, but for the PekWM hotkeys? I’ve done something like this, but I cannot make it work. Is it even possible?

    KeyPress = “Ctrl Up” { Actions = “Exec amixer -q set PCM 1+ unmute &” }
    KeyPress = “Ctrl Down” { Actions = “Exec amixer -q set PCM 1- unmute &” }
    KeyPress = “Ctrl Mod1 End” { Actions = “Exec amixer -q set PCM toggle &” }

  14. Rherison said

    I use a pipe menu to show de sound volume, and when I press Ctrl Alt s the pipe menu is activated.
    Is Ctrl Alt s for pipe menu of sound volume and other system informations.
    And is Ctrl Alt c for pipe menu that show me date and hour.

Leave a comment