Awesome FOSS Logo
Discover awesome open source software
Launched 🚀🧑‍🚀

Arch Adventures: Changing the volume with the buttons on a Logitech G930 Headset



tldr; I wrote a small script in python to use alsa command line tools to change the volume on my headset. A tool already exists that if faster and more robust. I should switch, but will I? who knows :).

I own and (mostly) happily use a Logitech G930:


While the support under linux is pretty good already (most buttons work, and perform their intended functions), I recently got fed up with the fact that the little scroll wheel on the G930 wasn’t actually changing the volume. Currently I can modify the volume of the headset through the ever-amazing Pulse Audio Volume Control (pavucontrol) application, but the actual on-headset scroll wheel isn’t working, and it’s a bit frustrating.

While there is probably some bit of configuration (hopefully) that could perform the mapping of my individual setup of ALSA+PulseAudio to correctly catch the XF86AudioRaiseVolume/XF86AudioLowerVolume buttons and increase/decrease the volume on the headphones, I decided this would be a good time to hack up a solution. In this case, the solution requires a few steps:

  1. Developing a small script that can incrementally increase or decrease the volume for the headset
  2. Hooking that script up to run when the XF86AudioLowerVolume button is received

Of course, #2 is very easy to accomplish by looking in Arch’s keyboard customization menus (Keyboard > Application Shortcuts), so that’s not the part we’re going to talk about today. Doing #1 was a great way to practice Python (and realize how much of it I’ve forgotten), and was a great exercise in writing a small but effective script to utilize available system binaries (the binaries that I didn’t write do the actual hard work of talking to the headset, of course).

After some digging and internet-searching, I found the magical command that would properly change the volume on my headset:

$ amixer -c 2 cset numid=4 50%

This command has a few facets, but the important things to note are:

  • 2 is the sound card number (you can find this information in the output of aplay -l)
  • cset is the subcommand used to set the property that represents the volume
  • the numid=4 bit gets the right property that corresponds to the volume that the headset is producing

The task broke down into a few simple sub-tasks:

  1. Use aplay -l to get the sound card number of the device that represents the headset.

  2. Use amixer to gather information, and find out how I can identify the property/control I actually want.

  3. Generate a shell command that uses amixer cset to set that property somewhat intelligently.

I’ll cut to the chase and post the Github snippet of the finished product here:

All in all, it was a fun little task to complete, and it gave me a little bit more knowledge on how to debug arch when it has issues with sound, which was fantastic.

As per usual, right after finishing this little script (while actually writing this blog post), I stumbled upon pamixer, which of course reduces all the effort I put forth to a proper command line tool with a good API and documentation:

$ pamixer -d 5 --sink 1

pamixer also came with extremely easy to use commands to determine which sinks and sources are available.

Now, I only need to decide if the last few hours were completely in vain or not. :)