-
Notifications
You must be signed in to change notification settings - Fork 2
/
battery-notifier.sh
executable file
·45 lines (40 loc) · 1.95 KB
/
battery-notifier.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
#please install acpi before using this ==> sudo apt install acpi
while true; do
export DISPLAY=:0.0
battery_level=$(acpi -b | grep -P -o '[0-9]+(?=%)')
ac_adapter=$(acpi -a | cut -d' ' -f3 | cut -d- -f1)
if on_ac_power; then #check if AC is plugged in
if [ $battery_level -ge 95 ]; then #check if the battery level is over 90%
notify-send -u critical "Please, kindly unplug your AC adapter" "Battery level: ${battery_level}%" -i battery-full-charged
# sleep 300
elif [ $battery_level -le 20 ]; then
notify-send -u critical "Thank you!!!" "You did an excellent job, Keep it up." -i battery-caution-charging
sleep 300 #sleep as charging upto 20 take 15 min max
# break
fi
#if [ $ac_adapter -eq "off" ]; then
# notify-send -u critical "AC Adapter" "The AC Adapter is off."
#fi
fi
if [ "$ac_adapter" == "off" ]; then
if [ $battery_level -le 20 ]; then #check if the battery level is over 90%
notify-send -u critical "Please, kindly plug-in your AC adapter" "Battery level: ${battery_level}%" -i battery-caution
# break
# sleep 180
elif [ $battery_level == 30 ]; then
notify-send -u critical "Please keep your AC adapter nearby ${battery_level}%" -i battery-caution
# break
# sleep 180
elif [ $battery_level == 40 ]; then
notify-send -u critical "Its ${battery_level}%" -i face-angel
# break
# sleep 180
elif [ $battery_level -ge 95 ]; then
notify-send -u critical "Thank you!!!" "You did an excellent job, Keep it up." -i face-angel
sleep 300 # sleep as charging is above 95
fi
fi
sleep 5 #wait for 300 seconds before checking again
done
#to add this to startup application ==> https://www.simplified.guide/gnome/automatically-run-program-on-startup