Skip to content

Instantly share code, notes, and snippets.

@janstuemmel
Created December 20, 2017 22:46
Show Gist options
  • Save janstuemmel/c391aa1b092f8bb0b188ec247f298a2e to your computer and use it in GitHub Desktop.
Save janstuemmel/c391aa1b092f8bb0b188ec247f298a2e to your computer and use it in GitHub Desktop.
openbox keyboard media keys
<openbox_config xmlns="http://openbox.org/3.4/rc" xmlns:xi="http://www.w3.org/2001/XInclude">
<!-- config ... -->
<keyboard>
<!-- in section keyboard add following: -->
<keybind key="XF86AudioLowerVolume">
<action name="Execute"><execute>amixer -q sset Master 3%-</execute></action>
</keybind>
<keybind key="XF86AudioRaiseVolume">
<action name="Execute"><execute>amixer -q sset Master 3%+</execute></action>
</keybind>
<keybind key="XF86AudioMute">
<action name="Execute"><execute>amixer -q -D pulse sset Master toggle</execute></action>
</keybind>
<keybind key="XF86AudioPlay">
<action name="Execute"><execute>dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause</execute></action>
</keybind>
</keyboard>
</openbox_config>
@ABelliqueux
Copy link

ABelliqueux commented Dec 3, 2022

Pulseaudio alternative

<keybind key="XF86AudioMute">
      <action name="Execute">
        <command>pactl set-sink-mute 0 toggle</command>
      </action>
    </keybind>
    <keybind key="XF86AudioRaiseVolume">
      <action name="Execute">
        <command>sh -c "pactl set-sink-mute 0 false ; pactl set-sink-volume 0 +5%"</command>
      </action>
    </keybind>
    <keybind key="XF86AudioLowerVolume">
      <action name="Execute">
        <command>sh -c "pactl set-sink-mute 0 false ; pactl set-sink-volume 0 -5%"</command>
      </action>
    </keybind>

Play/Pause, Next, Previous

If you want to use your play/next/prev keys with ALL your MPRIS compatible media software, you can use a client like playerctl to send these commands :

    <keybind key="XF86AudioPlay">
       <action name="Execute">
         <command>playerctl play-pause</command>
       </action>
    </keybind>
    <keybind key="XF86AudioPrev">
    <action name="Execute">
        <command>playerctl previous</command>
    </action>
    </keybind>
    <keybind key="XF86AudioNext">
      <action name="Execute">
        <command>playerctl next</command>
      </action>
    </keybind>

Screen brightness

If on a laptop, you can control the lcd brightness with light using :

First find your backlight device with

light -L | grep backlight

then use what you found in your command instead of 'intel_backlight' :

    <keybind key="XF86MonBrightnessUp">
    <action name="Execute">
        <command>light -As "sysfs/backlight/intel_backlight" 10</command>
    </action>
    </keybind>
    <keybind key="XF86MonBrightnessDown">
    <action name="Execute">
        <command>light -Us "sysfs/backlight/intel_backlight" 10</command>
    </action>
    </keybind>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment