Last active
November 3, 2018 16:00
-
-
Save pca2/a8368004035bd4c34a4c5a04e227d242 to your computer and use it in GitHub Desktop.
Linux Battery Unplug Reminder script (FruitJuice)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
#Adapted from https://linoxide.com/linux-how-to/remind-unplug-charging-laptop-arch-linux/ | |
# DEBUG=true #uncomment to enable logging | |
MIN_BAT=40 | |
MAX_BAT=80 | |
log(){ | |
datestamp=$(date +%Y-%m-%d_%H:%M:%S) | |
msg="$@" | |
echo "[$datestamp]- $msg" | |
} | |
debug_log (){ | |
if [ -n "$DEBUG" ]; then | |
log "$@"; | |
fi | |
} | |
debug_log "start" | |
while true ; do | |
debug_log "in loop" | |
UNPLUGGED=$(acpi -a | grep -i off-line) | |
BAT_PERCENTAGE=$(acpi|grep -Po "[0-9]+(?=%)") | |
debug_log "unplugged status: $UNPLUGGED" | |
debug_log "Current bat percentage: $BAT_PERCENTAGE" | |
if [ $BAT_PERCENTAGE -le $MIN_BAT ]; then # Battery under low limit | |
debug_log "bat low" | |
notify-send "Battery under $MIN_BAT%. Please plug in the adapter" | |
elif [ $BAT_PERCENTAGE -ge $MAX_BAT ]; then # Battery over high limit | |
debug_log "bat high" | |
if [ "$UNPLUGGED" == "" ]; then # plugged | |
debug_log "bat plugged" | |
notify-send "Battery above $MAX_BAT%. Please unplug the adapter" | |
fi | |
fi | |
debug_log "sleeping" | |
sleep 30 #Repeat every 30 seconds | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment