Skip to content

Instantly share code, notes, and snippets.

@ComradeCat24
Last active February 3, 2022 18:27
Show Gist options
  • Save ComradeCat24/0b9d8dc27ad9a9b3df9c136ce74cc466 to your computer and use it in GitHub Desktop.
Save ComradeCat24/0b9d8dc27ad9a9b3df9c136ce74cc466 to your computer and use it in GitHub Desktop.
Get Battery notification on Linux
#!/bin/bash
while true
do
export DISPLAY=:0.0
battery_level=`cat /sys/class/power_supply/BAT0/capacity`
if [ $(cat /sys/class/power_supply/BAT0/status) = 'Charging' ]; then
if [ $battery_level -ge 80 ]; then
notify-send -t 10000 "Battery Full" "Level: ${battery_level}%"
fi
else
if [ $battery_level -le 25 ]; then
notify-send -t 10000 --urgency=CRITICAL "Battery Low" "Level: ${battery_level}%"
fi
fi
sleep 60
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment