Files
omarchy/bin/omarchy-battery-monitor

31 lines
857 B
Plaintext
Raw Normal View History

2025-07-10 19:04:40 +02:00
#!/bin/bash
2025-07-10 15:36:30 -07:00
# Designed to be run by systemd timer every 30 seconds and alerts if battery is low
2025-07-10 19:04:40 +02:00
BATTERY_THRESHOLD=10
NOTIFICATION_FLAG="/run/user/$UID/omarchy_battery_notified"
get_battery_percentage() {
upower -i $(upower -e | grep 'BAT') | grep -E "percentage" | grep -o '[0-9]\+%' | sed 's/%//'
}
get_battery_state() {
upower -i $(upower -e | grep 'BAT') | grep -E "state" | awk '{print $2}'
}
send_notification() {
2025-07-10 15:36:30 -07:00
notify-send -u critical "Battery Low" "Time to recharge! (battery is at ${1}%)" -i battery-caution
2025-07-10 19:04:40 +02:00
}
BATTERY_LEVEL=$(get_battery_percentage)
BATTERY_STATE=$(get_battery_state)
if [[ "$BATTERY_STATE" == "discharging" && "$BATTERY_LEVEL" -le "$BATTERY_THRESHOLD" ]]; then
if [[ ! -f "$NOTIFICATION_FLAG" ]]; then
send_notification "$BATTERY_LEVEL"
touch "$NOTIFICATION_FLAG"
fi
else
rm -f "$NOTIFICATION_FLAG"
fi