"Little things seem nothing, but they give peace, like those meadow flowers which individually seem odorless but all together perfume the air." - Georges Bernanos
Every once in a while I run into a problem that needs the same kind of solution, so I wrote it. Here are my two examples:
- in KSET we have a setup where all desktops use pulseaudio. We also have a set of decent speakers mounted to a wall and connected to a tiny server that's also running pulseaudio, so that any computer can stream audio to those speakers. However, that's not supposed to be default, by default people should be able to use headphones or not stream audio at all. Since most people don't like having to open a terminal to do something as trivial as changing the default pulseaudio sink (and padevchooser got deprecated), we needed something more user friendly.
- I connected my mom's computer's HDMI output to the TV, which is connected to the living room sound system. That setup has 2 issues: when the second display is connected, menus from systray programs have parts going to the other screen and when the displays go to stand-by (after 10 minutes of idling) it cuts the sound that's going through HDMI to the sound system. Again, I don't want my mom to have to start a terminal every time she wants to listen to music, so I needed to give her a simple way of turning the HDMI output on and off while also switching DPMS and screensaver off and on.
The solution I came up with is imaginatively named systray-toggler and is available on GitHub. It's a small program that sits in the systray and rotates through a list of options, each of which has its own icon. When the option is selected the program runs a shell command if you specified one for that option. Left click on the icon selects the next option in the array and right click gives the menu with all the options.
In the pulseaudio case, it used the speaker and headphones icons and ran pax11publish to change the default sink. In the HDMI case, I "borrowed" a nice TV icon off the net and created 2 versions, one with the TV off and the other with the TV on. I wrote a small wrapper script around xrandr and xset commands and the program ran that. I literally spent more time working on the icons than adjusting the program to do what I needed it to.
And that's that. If you have a similar need, I hope this small piece of code helps you.