abidibo.net

Low battery notification with fluxbox

bash battery conky fluxbox

I'm very happy with my fluxbox window manager, but there is a thing which causes me some problems, the lack of a notification message when my laptop battery has a really low charge.

I run conky as monitor display, which shows me battery information, but while I'm working I don't care of my desktop most of the times, I'm overwhelmed by all my opened windows and applications and so always happens that my machine shutdown because my battery dies without my knowledge.

So here comes a script which notifies me when the battery charging is below 14%.

Requirements

The bash script requires two commands to work: acpi and notify-send.

In order to install them on debian/ubuntu type

$ sudo apt-get install acpi notify-osd

The script

Here it is: battery_notify.sh

#!/bin/bash
battery_info=$(acpi -V | grep Battery | awk 'NR==1')
battery_status=$(echo $battery_info | sed 's/^Battery 0: \([a-zA-Z]*\)\(.*\)/\1/') # Charging | Discharging
battery_percentage=$(echo $battery_info | sed 's/^Battery 0: [a-zA-Z]*, \([0-9]*\)%.*/\1/')
if [ $battery_status == "Discharging" -a $battery_percentage -lt 14 ]
  then
    notify-send "WTF Battery Low" "Plug in your FUKKA AC adapter!"
fi

Remember to give it the execution privilege:

$ chmod +x battery_notify.sh

Use it

Such script must be invoked every n minutes, so you may create a cron job, or, if you use a monitor display application like conky, you can just call it from there. For example add the following line to your conkyrc:

${execi 180 ~/utilities/battery_notify.sh}

This way the script runs every 3 minutes, I think can be a good time interval. Enjoy!

Subscribe to abidibo.net!

If you want to stay up to date with new contents published on this blog, then just enter your email address, and you will receive blog updates! You can set you preferences and decide to receive emails only when articles are posted regarding a precise topic.

I promise, you'll never receive spam or advertising of any kind from this subscription, just content updates.

Subscribe to this blog

Comments are welcome!

blog comments powered by Disqus

Your Smartwatch Loves Tasker!

Your Smartwatch Loves Tasker!

Now available for purchase!

Featured