↓ Skip to main content

Adjusting volume using mediakeys in openbox

·264 words·2 mins
Sergii Zolotarov
Author
Sergii Zolotarov
Twenty years of Java, from Kyiv to Leeuwarden. Currently at Booking.com

Recently I’ve stepped away from the shiny linux desktop environments into a geeky openbox. Black screen and mouse pointer. Nothing that distracts you from work. Trying to do as much as possible from the term as well. This goes for volume controls as well. I’ve discovered a lot of details about sound and mixing :) It appears volume is relative, especially if you have a lot of sources and sinks. Such simple thing as volume that’s presented by a desktop environment is exposed to you in the form of sinks and inputs outputs by pulseaudio. So I had to study the subject a bit and with some trial and error found the sweet spot in taming all the seakers/headphones/bluetooth:


<keybind key="XF86AudioMute">
  <action name="Execute">
    <command>sh -c "pactl list sinks | grep 'Sink #' | cut -d'#' -f2 | xargs -I@ pactl -- set-sink-mute @ toggle"</command>
  </action>
</keybind>
<keybind key="XF86AudioLowerVolume">
  <action name="Execute">
    <command>sh -c "pactl list sinks | grep 'Sink #' | cut -d'#' -f2 | xargs -I@ pactl -- set-sink-volume @ -2000"</command>
  </action>
</keybind>
<keybind key="XF86AudioRaiseVolume">
  <action name="Execute">
    <command>sh -c "pactl list sinks | grep 'Sink #' | cut -d'#' -f2 | xargs -I@ pactl -- set-sink-volume @ +2000"</command>
  </action>
</keybind>

So far I’m using only one player for terminal, but in the future I plan to add play/pause next/prev shortcuts for YoutubeMusic (its the one that sits in your browser, aha).


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

First published on the old anydoby.com blog on 2019-04-21.