Is there any way to get notified when battery is full? [duplicate]

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.


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.