Basic Power Management Script

Fri 30 January 2015

I mentioned previously that I'm back to using the Spectrwm tiling window manager on the laptop. So there I was the other day doing some work on it when suddenly out of the blue the system died. Turns out I hadn't connected it to the power supply and it was running on battery juice. I had also forgotten that lighweight window managers don't come with elaborate power management tools! What to do?

In the past when using Openbox/Fluxbox I remember conscripting the Xfce Power manager to do the job. This time I wanted to script at least some of the essential functionality, myself. So I created a python script to do the job. The script notifies the user (via sound and OSD) when the battery is running low and when the battery drops to critical levels automatically initiates shutdown. Also, it will be put the system into standby if it is running on battery and has been inactive (no user input in X) for a certain defined period.

I wrote it intending to launch it via my .xinitrc script and it utilises the notification daemon so it will only function fully when running inside an X session. I'm using xscreensaver to suspend my screen after a period of inactivity so haven't bothered scripting that facilitiy in. If you want to set this manually you can use xset as described here. Script has been tested to work on my Debian Jessie system but should work on fine on other systemd distros with minimal wrangling.

The script can be found on my github.