Set the volume in OpenBox/LXDE (or on the command line) with PulseAudio and Ubuntu

I am switching to LXDE, and enjoying it, but a few things require some manual config before it’s just how I like it.

To control the sound volume with the volume buttons, the default LXDE config in ~/openbox/lxde-rc.xml contains an entry like this:

<!-- Doesn't work for me -->
<keybind key="XF86AudioRaiseVolume">
  <action name="Execute">
    <command>amixer -q sset Master 3%+</command>
  </action>
</keybind>

(Inside the <keyboard> section.)

This doesn’t work for me, but we can do it by sending a command to PulseAudio, using the pactl command. The command to increase the volume is:

pactl -- set-sink-volume 0 +5%

To decrease the volume, put “-5%” instead of “+5%”. Note that if you have more than one enabled audio sink you might need to change the “0″ to a “1″ or something else. Running pactl stat should help you here.

[Beware of bug 686667, meaning you can't use pacmd and you must have the -- at the beginning.]

So the correct recipe for your OpenBox config in ~/openbox/lxde-rc.xml is:

<keybind key="XF86AudioRaiseVolume">
  <action name="Execute">
    <command>pactl -- set-sink-volume 0 +5%</command>
  </action>
</keybind>
<keybind key="XF86AudioLowerVolume">
  <action name="Execute">
    <command>pactl -- set-sink-volume 0 -5%</command>
  </action>
</keybind>

After editing this file you can run:

openbox --reconfigure

To update without restarting OpenBox.

Of course, because I don’t have volume control buttons, I want my volume to change with Ctrl-Alt-PageUp and Ctrl-Alt-PageDown, so I use this recipe:

<keybind key="C-A-Prior">
  <action name="Execute">
    <command>pactl -- set-sink-volume 0 +5%</command>
  </action>
</keybind>
<keybind key="C-A-Next">
  <action name="Execute">
    <command>pactl -- set-sink-volume 0 -5%</command>
  </action>
</keybind>

but that’s just me.

Leave a Reply