Skip to content

Instantly share code, notes, and snippets.

@ffflorian
Last active October 7, 2017 06:16
Show Gist options
  • Save ffflorian/0a52bc7edde6da69b2f6 to your computer and use it in GitHub Desktop.
Save ffflorian/0a52bc7edde6da69b2f6 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment