-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbattery-alert.sh
More file actions
45 lines (33 loc) · 1.12 KB
/
Copy pathbattery-alert.sh
File metadata and controls
45 lines (33 loc) · 1.12 KB
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
#!/bin/bash
# Warning levels (high → low)
LEVELS=(20 15 10 8)
SOUND_FILE="/usr/share/sounds/freedesktop/stereo/dialog-warning.oga"
CHECK_INTERVAL=60 # check every minute
# Track which levels have already warned
declare -A WARNED
for lvl in "${LEVELS[@]}"; do
WARNED[$lvl]=false
done
while true; do
CAPACITY=$(cat /sys/class/power_supply/BAT0/capacity)
STATUS=$(cat /sys/class/power_supply/BAT0/status)
# Only warn when discharging
if [ "$STATUS" = "Discharging" ]; then
for lvl in "${LEVELS[@]}"; do
if [ "$CAPACITY" -le "$lvl" ] && [ "${WARNED[$lvl]}" = false ]; then
# Send notification
notify-send -u critical "Low Battery" "Battery is at ${CAPACITY}%"
# Play calm alert sound
paplay "$SOUND_FILE"
# Mark this level as warned
WARNED[$lvl]=true
fi
done
else
# Reset all warnings when charging
for lvl in "${LEVELS[@]}"; do
WARNED[$lvl]=false
done
fi
sleep "$CHECK_INTERVAL"
done