zloy-zhake
10/7/2017 - 6:16 AM

Linux Mint Cinnamon: Display a notification when battery is running low

Linux Mint Cinnamon: Display a notification when battery is running low

# Original from http://unix.stackexchange.com/questions/60778/how-can-i-get-an-alert-when-my-battery-is-about-to-die-in-linux-mint
# Added a second notification
#!/bin/bash

POWERSUPPLY="/sys/class/power_supply/AC/online"
STATUS_LOW=25
STATUS_CRITICAL=10
NOT_CHARGING="0"
ICON_LOW="/usr/share/icons/Mint-X/status/scalable/battery-low-symbolic.svg"
ICON_CRITICAL="/usr/share/icons/Mint-X/status/scalable/battery-empty-symbolic.svg"

export DISPLAY=:0

BATTERY_LEVEL=$(acpi -b | grep -P -o '[0-9]+(?=%)')
STATUS=$(cat $POWERSUPPLY)

if [ $BATTERY_LEVEL -le $STATUS_CRITICAL -a $STATUS = $NOT_CHARGING ]
then
    notify-send -u critical -i "$ICON_CRITICAL" -t 3000 "Battery level is at ${BATTERY_LEVEL} %!"
elif [ $BATTERY_LEVEL -le $STATUS_LOW -a $STATUS = $NOT_CHARGING ]
then
    notify-send -u normal -i "$ICON_LOW" -t 3000 "Battery level is at ${BATTERY_LEVEL} %!"
fi

exit 0