Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Sometimes my charger remains plugged into laptop even after charging is complete.

Is there a way to get a pop-up message/notification when my battery gets full due to charging or is there any software/package which can provide the functionality?

share|improve this question
up vote 6 down vote accepted

Install the acpi package. Now put this in and make it executable:

acpi -V
if cat /proc/acpi/battery/BAT1/state | grep "charging state" | grep -vE ":[\t ]*charging$"; then
    exit 1
    exit 0

If echo -e "\a" makes a sound, start this when you want to watch the battery status:

watch --beep

If it doesn't make any sound or you want a notification and a better alarm than whatever watch can provide, install libnotify-bin and mplayer and use this instead:

watch --errexit; notify-send "Finished charging" && mplayer -msglevel all=0 -loop 0 /usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga


If you look at the man page for grep you can see that -v reverses the matching, and therefore the return/status code. -E means it's a regular expression. the [\t ] in the regex (regular expression) means "tab or space". The following star makes it mean "tab or space 0 or more times". The trailing "$" means that it should match the end of the line. The final grep means that lines NOT ending in a ":", any number of tabs or spaces and then "charging" and the end of the line should make grep exit with status code 0. This means that grep will return 1 as long as the computer is charging. The if will execute it's first branch when the status code is 0, which means we are effectively negating the result of grep, since we exit 1 when grep exits 0 and exit 0 when grep exists non-zero.

share|improve this answer
if you want these commands explained, just ask me – Janus Troelsen Jul 31 '12 at 20:06
i m not sure what this grep -vE ":[\t ]*charging$" will do. Could you please explain the commands. thanks – Ankit Aug 1 '12 at 6:00
added explanation – Janus Troelsen Aug 1 '12 at 11:02
And where is this file? Or if I create it, is there a specific place I have to save it? – Parto Feb 14 '14 at 15:32
@AvatarParto: doesn't matter where. name doesn't matter either, as long as you change it everywhere – Janus Troelsen Feb 15 '14 at 1:38

I have written a small script that will do that:



#!/usr/bin/env bash
while true
    export DISPLAY=:0.0
    battery_percent=$(acpi -b | grep -P -o '[0-9]+(?=%)')
    if on_ac_power; then
        if [ "$battery_percent" -gt 95 ]; then
            notify-send -i "$PWD/batteryfull.png" "Battery full." "Level: ${battery_percent}% "
    sleep 300 # (5 minutes)



sudo apt-get install acpi
git clone
cd battery-full-notification/
chmod +x

Copy the script to ~/bin folder (why the ~/bin folder?) :

cp batteryfull.* ~/bin

Or copy it to /usr/local/bin if you want it to be available for all users on your computer:

cp batteryfull.* /usr/local/bin

Then add script as a startup application by:

  • Open Dash
  • Search for Startup Applications
  • Double-click the icon
  • Click Add and fill in as follows:

    startup application batteryfull

share|improve this answer

Your Answer


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.