summaryrefslogtreecommitdiff
path: root/scripts/system/monitor-battery
blob: 94b7365eaacba2517347344326cdd92271ca2346 (plain)
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
#!/bin/sh

threshold=20
very_low_threshold=10

amount="low"
prev_cap=100

while true; do
	cap=$(cat /sys/class/power_supply/BAT0/capacity)
	status=$(cat /sys/class/power_supply/BAT0/status)

	# when capacity changes
	if [ $cap -ne $prev_cap ]; then

		# notify when drop under threshold
		if [ $cap -lt $threshold ] && [ $prev_cap -ge $threshold ]; then
			notify-send "Plug In" "Battery has fallen under $threshold%"
		fi
	
		# notify every percent if very low
		if [ $cap -le $very_low_threshold ] && [ $status -ne "Charging" ]; then
			notify-send "BATTERY LOW" "Battery is at $bat%"
		fi

	fi

	prev_cap=$cap
	sleep 10
done