add script check_battery

This commit is contained in:
Guilherme Rugai Freire 2024-09-03 12:07:11 -03:00
parent dfe8069718
commit 6de5431477
No known key found for this signature in database
GPG Key ID: AC1D9B6E48E16AC1
3 changed files with 27 additions and 0 deletions

1
bin/check_battery Symbolic link
View File

@ -0,0 +1 @@
../check_battery/check_battery.sh

9
check_battery/README.md Normal file
View File

@ -0,0 +1,9 @@
# check_battery
## About
Check the battery percentage and notify user if it is about to end.
## Requirements
- notify-send
- mpv
- UPower

17
check_battery/check_battery.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
DEVICE="/org/freedesktop/UPower/devices/battery_BAT0"
time="$(upower -i $DEVICE | grep time | cut -d':' -f2 | tr -s ' ' | cut -c2-)"
perc="$(upower -i $DEVICE | grep percentage | awk '{print $2}' | tr -d '%')"
stat="$(upower -i $DEVICE | grep state | awk '{print $2}')"
if [ "$perc" -le "20" ]; then
urgency="normal"
if [ "$perc" -le "10" ]; then
urgency="critical"
fi
notify-send -u "$urgency" --icon="battery" "Battery is low ($perc%)" "Time remaining is $time."
mpv /usr/share/sounds/freedesktop/stereo/dialog-information.oga
fi