Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

I'm using Ubuntu 12.04 on a laptop, I was wondering if there is a way to get notified when the battery become full.

share|improve this question

marked as duplicate by Glutanimate, Tim, mikewhatever, Eliah Kagan, Eric Carvalho Aug 18 at 10:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
This can be done by running a script. But first i need to know which type of battery you are using.Open terminal.type ls /proc/acpi/battery/. What is the output? –  Khurshid Alam Jun 14 '12 at 19:17

1 Answer 1

up vote 1 down vote accepted

This feature was present on old gnome2, but mising from latest gnome.Gnome power manager is supposed to give notification when battery is full, but it doesn't(It could be a bug). I couldn't find any option with dconf either.To me it appears that the only way to achieve this through a cron job which regulary checks whether battery is full or not.

First open terminal & type ls /proc/acpi/battery/. In my case, the output is C241. Your could be different(generally batt0 ot batt1).Also check the type of ac adapter,ls /proc/acpi/ac_adapter. Its C240 for me. Open gedit & copy the following script.

Remember to replace C241 & C240 with your battery type & ac adapter.

#!/bin/bash

cd ~/.scripts
notification=$(grep 'notification:' notification|awk '{print $2}')

cd /proc/acpi/ac_adapter/C240;
power=$(grep 'state:' state|awk '{print $2}')
s1="$power"

s2="charged"
s3="on-line"
s4="on"

export DISPLAY=:0

if [ "$s1" = "on-line" ]; then
  cd /proc/acpi/battery/C241;
  state=$(grep 'charging state:' state|awk '{print $3}')
  if [ $state = $s2 ] && [ "$notification" = "$s4" ];
    then
            notify-send  --urgency=critical "Power Manager" "battery is full" -i battery_full
            echo "notification: off" >~/.scripts/notification

    fi

else
  if [ $notification != "on" ]; then
    echo "notification: on" >~/.scripts/notification
  fi
fi

save the file as batteryfull.sh at ~/.scripts (or anywhere you like). Make the file executable chmod a+x batteryfull.sh.

On terminal type echo "notification: on" >~/.scripts/notification. Also add the same line at the end of your ~/.profile.

Install gnome-schedule (sudo apt-get install gnome-schedule).Launch it, choose new task & select "a task that launches recuurently". On command section put full path of the script file.In my case its ~/.scripts/batteryfull.sh.You can set corn-job duration every min or every 5 min.click apply.You can check running jobs by typing crontab -l in terminal.

gnome-schedule

You can run this script at every boot by adding gnome-schedule as a startup application(may not be required in your case).

Note: This is probably not the perfect way to do this, but it works.So far this much i can do with my little knowledge with bash scripting.I will improve the script if i find something better.

share|improve this answer
    
Try setting an envorinment variable(or even a file) when the battery is full, and when the battery starts depleting, reset it so that the notification can be retriggered when the battery is full again. –  hexafraction Jun 14 '12 at 22:07
    
Initially that was my plan.I made system-wide variable like "export NOTIFICATION=on" & added to ~/.profile.But couldn't able to change(set /unset) that variable from bash script. Finally I created a separate file & read the data from there. –  Khurshid Alam Jun 15 '12 at 13:30
    
thank you, it works after adding the notification file using echo "notification: on" >~/.scripts/notification –  sohaibafifi Jun 15 '12 at 20:42

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