My *nix world

X11 battery status

If you are using a laptop (like me) then you know that is important to be notified (eg. a message) whenever your AC is plugged/unplugged or when your battery has less than 30% power (or whatever % triggers you). I think all the Linux distro have an applet/pluggin which can take care about this by usually they consume more resources than my simple solution I propose bellow:

  • a simple bash script (eg: battery_status) which check every 5 seconds (customizable) the battery status a print a notification balloon on your screen
  • load that script at session start up (so it will run as long your session runs) so it will monitor your battery status all the time

The script:

Start the script at session start-up

In Xfce you can set up a Application Autostart (which are supposed to start at session start up):

  • Settings -> Session and Startup -> Application Autostart tab
  • define a new application autostart as bellow:
    • name: battery_status (in fact it doesn't matter how you will name it)
    • command: battery_status (specify also the path if the script cannot be found on PATH)

So, the script will start when your X session starts and then will run in background every 5 seconds (or whatever ALERT_LIMIT_FREQ you would like).

Depending on the battery status a notification balloon like the one bellow can be shown:

battery status
Edit 21.Feb.2013: I've changed a bit the original script and the current version (above) allows one to invoke this script followed by an immediate exit. That way, in addition to the script main loop that track your battery status, one could invoke the script with an argument "q" which will display the current status then exit:

So I've created a desktop shortcut (like CTRL+ALT+B) that shows immediately the battery status then leave, while the session script instance still running in background, watching the battery status and informing me whenever necessary.

Now, if you think that this article was interesting don't forget to rate it. It shows me that you care and thus I will continue write about these things.

The following two tabs change content below.
X11 battery status

Eugen Mihailescu

Founder/programmer/one-man-show at Cubique Software
Always looking to learn more about *nix world, about the fundamental concepts of math, physics, electronics. I am also passionate about programming, database and systems administration. 16+ yrs experience in software development, designing enterprise systems, IT support and troubleshooting.

Leave a Reply

Your email address will not be published. Required fields are marked *


Get every new post on this blog delivered to your Inbox.

Join other followers: