#! /bin/bash
# Read battery percentage value
OUT=`upower -i /org/freedesktop/UPower/devices/battery_BAT1 | grep percentage`
# Select only the int value
IFS=':' read -ra P <<< "$OUT"
PERCENTAGE="%"
BATTERY_VALUE=${P[1]%$PERCENTAGE}
# Send a notification if battery level is under 15% and not on AC power
if ! on_ac_power; then
if (($BATTERY_VALUE < "15")); then
eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)";
notify-send -u critical -i "battery-caution" "Battery low! You should plug in your laptop!"
/usr/bin/aplay /usr/share/sounds/desktop-logout.oga
fi
fi
# Send a …
Run Code Online (Sandbox Code Playgroud)