Making peace with your partner, when you share an office
Posted by Elf Sternberg as Linux
I have a bad habit. I leave the music playing on my desktop all the time. My wife shares the office, and she’s a professional podcaster, so this habit does not please her in the least. Fortunately, I have found a technological solution.
This solution is for Linux and Audacity. You may be able to adapt it to other music programs, but as it exploits a feature of X Windows, using it on non-X distros might be tricky. The secret is to exploit the X-MIT-SCREEN-SAVER hook in X. This is the published X atom to notify various listening programs when the mouse and keyboard have been idle for a set amount of time, which, as you might imagine, is pretty useful for the screensaver. But the value is published locally to any subscribed program being run by the current user, and there’s a command-line tool that allows you to run any arbitrary program after a given period of time, xidle.
Xidle is simple, but it needs help. If you just put audacious into its command line, it’ll start audacious when you’re not listening to it. That’s not good. So you need a script:
#!/bin/bash PIDS=`/bin/ps cax | /bin/grep audacious | /bin/grep -o '^[ ]*[0-9]*'` if [ -n "$PIDS" ]; then /usr/bin/audacious -u > /dev/null 2>&1 fi
I named this “audi-pip,” so it wouldn’t conflict with the grep string. Make sure to chmod it to 0755 so it’ll run. Then configure xidle:
xidle -program /home/<you>/bin/audi-pip -timeout 300
If you’re really old-school, like me, you could put this line above your window manager in .xinitrc, but don’t forget to put an & at the end. Now, if you’re idle for more than five minutes and you’ve left audacious running, it will be paused. And audacious is pretty smart; it’ll automatically restart when you un-idle.