aboutsummaryrefslogtreecommitdiff
path: root/bin/battery_check
diff options
context:
space:
mode:
Diffstat (limited to 'bin/battery_check')
-rwxr-xr-xbin/battery_check32
1 files changed, 19 insertions, 13 deletions
diff --git a/bin/battery_check b/bin/battery_check
index af44108..7d77b82 100755
--- a/bin/battery_check
+++ b/bin/battery_check
@@ -1,17 +1,23 @@
#!/usr/bin/env bash
-# Simple script to monitor the battery's status
+# Simple script to monitor the battery's status and level
-# calls batt_status script
-batt=$(acpi | awk '{print $4}' | sed -e 's/\%,//g')
-state=$(acpi | awk '{print }' | sed -e 's/\,//g')
+interval=300 # 5 minutes
+critical_level=7
-if [[ $batt -ge 99 ]]; then
- notify-send "Bateria" "Completamente carregada! (100%)"
-elif [[ $batt -eq 20 ]] ; then
- notify-send "Bateria descarregando" "Nível de bateria alcançou 20%"
-elif [[ $batt -eq 10 ]] ; then
- notify-send "Bateria descarregando" "Nível de bateria alcançou 10%"
-elif [[ $batt -le 5 ]]; then
- notify-send "Bateria crítica!" "Nível de bateria alcançou 5%"
-fi
+while true
+do
+ batt="$(cat /sys/class/power_supply/BAT0/capacity)"
+ state="$(cat /sys/class/power_supply/BAT0/status)"
+
+ if [[ $batt -ge 99 ]]; then
+ notify-send -u normal"Bateria" "Completamente carregada! (100%)"; pkill -RTMIN+20 dwmblocks
+ elif [[ $batt -eq 20 ]] ; then
+ notify-send -u normal "Bateria descarregando" "Nível de bateria alcançou 20%"; pkill -RTMIN+20 dwmblocks
+ elif [[ $batt -eq 10 ]] ; then
+ notify-send -u normal "Bateria descarregando" "Nível de bateria alcançou 10%"; pkill -RTMIN+20 dwmblocks
+ elif [[ $batt -le "$critical_level" ]]; then
+ notify-send -u critical "Bateria crítica!" "Nível de bateria alcançou 7%"; pkill -RTMIN+20 dwmblocks
+ fi
+ sleep "$interval"
+done