aboutsummaryrefslogtreecommitdiffstats
path: root/bin/lowbat
blob: 8c274da2b2f0e470aafee45a4161201189603122 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/sh

notify() {
	notify-send "Low battery" "Please plug in computer" -u critical -t 15000
	echo "beep beep - low battery" | espeak
}

while [ 1 ]; do
	acstat=$(acpi | awk '{print $3}' | rev | cut -c 2- | rev)
	batlvl=$(acpi | awk '{print $4}' | rev | cut -c 3- | rev)
	while [ "$acstat" = "Discharging" ]; do
		if [ $batlvl -lt 15 ]; then
			$(notify)
			sleep 20
			acstat=$(acpi | awk '{print $3}' | rev | cut -c 2- | rev)
			batlvl=$(acpi | awk '{print $4}' | rev | cut -c 3- | rev)
			if [ "$acstat" = "Charging" ]; then
				break
			fi
		fi
	done
	sleep 240
done