battery-monitor (657B)
1 #!/usr/bin/env bash 2 3 # Device path from 'upower -e' 4 BATTERY_PATH="/org/freedesktop/UPower/devices/DisplayDevice" 5 6 # Get initial battery percentage 7 get_battery_percentage() { 8 busctl get-property org.freedesktop.UPower "$BATTERY_PATH" org.freedesktop.UPower.Device Percentage | 9 awk '{print int($2)}' 10 } 11 12 while true; do 13 PERCENT=$(get_battery_percentage) 14 15 if [[ $PERCENT -le 10 ]]; then 16 notify-send -u critical "Battery Low" "Battery at ${PERCENT}%" -i battery-caution -t 30000 17 # Wait 5 minutes before rechecking to avoid spam 18 sleep 300 19 else 20 # Check every minute otherwise 21 sleep 60 22 fi 23 done