Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This happens to me more than I'd like to admit, but sometimes I don't notice the power getting low since it only shows up in my status bar, then the computer just quits. I'd like a big alert that warns me before this happens. Is there any way for it to alert me? Ubuntu has a nice popup that tells you it's getting low.

share|improve this question
    
Configure the power-manager from your desktop environment to do "something" - this can usually range from "nothing", over "run a command", to "hibernate"/"power off". –  peterph Jan 9 '13 at 19:33
    
Which desktop environment? –  Renan Jan 10 '13 at 0:17
    
@peterph I only have the "Power off" and "Hibernate" options. –  Travis R Jan 10 '13 at 2:22
    
@Renan running Cinnamon. –  Travis R Jan 10 '13 at 2:23
    
@TravisR sorry, I meant to say configure the behaviour when critical battery level is reached –  peterph Jan 10 '13 at 8:33

6 Answers 6

write a script!

battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`
if [ $battery_level -le 10 ]
then
    notify-send "Battery low" "Battery level is ${battery_level}%!"
fi

then cron it to run every few minutes or so. But yeah, if you can do it through the GUI, that's probably a much better way of doing it.

share|improve this answer

I had that same problem and I figured out a workaround. I installed from Linux Mint repositories an app called GKrellM. It monitors lots of stuff on your machine and there is battery. Setup with alarms, it works for me like a charm.

more info at:

http://www.gkrellm.net/

share|improve this answer

As I don't have Gnome Shell or Cinnamon installed, I cannot be of direct help as accessing the source could would be much practical since it's rather easy adding such a rudimentary extension with JavaScript.

You should open :

/usr/share/cinnamon/js/ui/status/power.js

and search for percentageText - subsequently, you ought to be able to add a pop-up message or alert.

share|improve this answer
    
Interesting, didn't know this stuff is in javascript. But no /status directory and no power.js I can find anywhere in the /cinnamon/js directories. –  Travis R Jan 12 '13 at 18:09
    
Have you tried to search for it from root using : find / -type f -name power.js –  nesyphlopanuri Jan 13 '13 at 14:32
    
Ran that, nothing found. –  Travis R Jan 14 '13 at 22:46

The issue is related at KDE environment. I have the same problem with MintMAYA KDE_version. When I worked with Mint9_Gnome a very useful pop-up appeared when a certain level of low-power was reached (auto-configured out_of_the_box on fresh installs). Very very annoying being shutted down without advice and no help founded even googling a lot :(

share|improve this answer

(This would be a comment, but I do not have enough reputation)

re: hdgarrood 's answer, setting cron to run notify-send actually turned out to be painfully finicky. (I think crontab -e does persist across reboots by default, fortunately). I followed several guides, I'm not sure what exactly fixed it in the end, but here is my full setup for running the checker every 5 minutes:

$ crontab -e

*/5 * * * * sh /home/nrw/.notify-send_setup
*/5 * * * * sh /home/nrw/.battnotif

$ cat .notify-send_setup

#!/bin/bash
touch $HOME/.dbus/Xdbus
chmod 600 $HOME/.dbus/Xdbus
env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.dbus/Xdbus
echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.dbus/Xdbus

exit 0

$ cat .battnotif

#!/bin/bash
export DISPLAY=:0
XAUTHORITY=/home/nrw/.Xauthority

if [ -r "$HOME/.dbus/Xdbus" ]; then
    . "$HOME/.dbus/Xdbus"
fi

battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`

# I tried to only notify when not charging, but could not get it to work
# STATUS=$(cat /sys/class/power_supply/ADP1/online)
# if [ $battery_level -le 15 ] && [ $STATUS == "0" ]

if [ $battery_level -le 15 ]
then
    /usr/bin/notify-send -u critical "Battery low" "Battery level is ${battery_level}%!"
    echo 'batt low' >> /home/nrw/cron.log
fi

echo 'ran batt' >> /home/nrw/cron.log

Make sure to chmod +x the bash scripts.

share|improve this answer

(This would be a comment to orangenarwhals answer, but I do not have enough reputation either..)

I do now run the following:

$ crontab -e
*/5 * * * * /home/<my username>/bin/checkLowBattery

$ cat /home/<my username>/bin/checkLowBattery
#!/bin/bash

POWERSUPPLY="/sys/class/power_supply/ACAD/online" # could be different on your system!
TOO_LOW=20 # how low is too low?
NOT_CHARGING="0"
ICON="/usr/share/icons/ubuntu-mono-dark/status/24/battery-low.svg" # eye candy

export DISPLAY=:0

BATTERY_LEVEL=$(acpi -b | grep -P -o '[0-9]+(?=%)')
STATUS=$(cat $POWERSUPPLY)

if [ $BATTERY_LEVEL -le $TOO_LOW -a $STATUS = $NOT_CHARGING ]
then
    /usr/bin/notify-send -u critical -i "$ICON" -t 3000 "Battery low" "Battery level is ${BATTERY_LEVEL}%!"
fi

exit 0

As you can see this is just orangenarwhals code with some changes:

  • no dbus trickery, somehow I didn't need it
  • put some "constants" into variables at the beginning of code
  • implemented warnings only when battery is not charging (take a look at man test, it explains how to do ANDs, among other things.)
  • added icon (find some candidates on your system with something like: $ find /usr/share/icons/ -iname "*batt*low*")
  • expiry-time in milliseconds

don't forget to chmod +x your scripts, you can then run them directly from cron(tab), no need for sh.

(This works on Ubuntu using Xmonad.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.