Русский English Tags View Sergey Zolotaryov's profile on LinkedIn Sign-in
Adjusting volume using mediakeys in openbox
Permanent link 21-04-2019 anydoby java linux openbox

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>

Add a comment

Previous article Reporting progress from Java applications in console Next article How to convert JPG's to a single PDF in Linux without losing quality