-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpower_alert.sh
executable file
·46 lines (39 loc) · 1.18 KB
/
power_alert.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
46
#!/bin/sh
# Set `CRITICAL_THRESHOLD' to the value of battery for which you want
# to be notified if level goes below. Similarly set `SAFE_THRESHOLD'
# for safe value.
# You will be notified by `notify-send' utility to
# send system notifications whenever battery
# crosses. `CRITICAL_THRESHOLD' value.
ALERT_SENT=0
CRITICAL_THRESHOLD=25
SAFE_THRESHOLD=80
# Global variables which might be used by other applications.
export BAT_CRITICAL=0
export BAT_SAFE=0
export BAT_NORMAL=0
while true; do
BAT_STATUS=$(cat /sys/class/power_supply/BAT0/capacity)
# Set environment variables.
if [ $BAT_STATUS -lt $CRITICAL_THRESHOLD ]; then
if [ $ALERT_SENT -eq 0 ]; then
notify-send -u critical "Battery less than $CRITICAL_THRESHOLD%."
ALERT_SENT=1
fi
export BAT_CRITICAL=1
export BAT_SAFE=0
export BAT_NORMAL=0
else
ALERT_SENT=0
if [ $BAT_STATUS -gt $SAFE_THRESHOLD ]; then
export BAT_CRITICAL=0
export BAT_SAFE=1
export BAT_NORMAL=0
else
export BAT_CRITICAL=0
export BAT_SAFE=0
export BAT_NORMAL=1
fi
fi
sleep 1m
done &