Quantcast
Channel: How can I get notification when my laptop battery gets fully charged? - Ask Ubuntu
Viewing all articles
Browse latest Browse all 5

Answer by hg8 for How can I get notification when my laptop battery gets fully charged?

$
0
0

I have written a small script that will do that:

screenshot


Script:

#!/usr/bin/env bash
while true
do
    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}% "
        fi
    fi
    sleep 300 # (5 minutes)
done

Installation:

Run:

sudo apt-get install acpi
git clone https://github.com/hg8/battery-full-notification.git
cd battery-full-notification/
chmod +x batteryfull.sh

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 batteryfull.sh 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


Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>