From 977a459ddaa33a856255be9c15464f0a5937c06c Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Mon, 19 Feb 2024 22:32:41 +0000 Subject: Add scripts to repo --- bin/battery-notify.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 bin/battery-notify.sh (limited to 'bin/battery-notify.sh') diff --git a/bin/battery-notify.sh b/bin/battery-notify.sh new file mode 100755 index 0000000..ed07119 --- /dev/null +++ b/bin/battery-notify.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +last="NONE" + +low=15 +critical=5 + +bat="BAT1" + +while true; do + + battery="/sys/class/power_supply/$bat" + if [ -d $battery ]; then + + capacity=$(cat $battery/capacity) + status=$(cat $battery/status) + + if [ "$last" != "FULL" ] && [ "$status" = "Full" ]; then + notify-send "Power" "Battery is full" + last="FULL" + fi + + # If low and discharging + if [ "$last" != "LOW" ] && [ "$status" = "Discharging" ] && \ + [ $capacity -le $low ]; then + notify-send "Power" "Battery warning: $capacity%" + last=LOW + fi + + # If critical and discharging + if [ "$status" = "Discharging" ] && [ $capacity -le $critical ]; then + notify-send "Power" "Battery critical: $capacity%" + last=CRITICAL + fi + fi + sleep 60 +done -- cgit v1.2.3-70-g09d2