#!/bin/sh # This script sends notifications when battery is low, # but only while discharging. battery=$(upower -e | grep BAT | head -n 1) percentage=$(upower -i "$battery" | awk '/percentage/ {gsub(/%/, "", $2); print $2}') state=$(upower -i "$battery" | awk '/state/ {print $2}') # Only notify if the battery is discharging [ "$state" != "discharging" ] && exit 0 if [ "$percentage" -le 5 ]; then notify-send "Battery very low." elif [ "$percentage" -le 15 ]; then notify-send "Battery low." fi