~scripts
55 itemsDownload ./*

55 itemsDownload ./*

..
dzen2
tiling
vosh
4cdl
4trips
alarm
ambient
ana-wall.sh
battery-monitor
brightness.sh
checkit
cleverbot.py
clock
color-gen
colors-hex
colorscheme.sh
compton
dailywall
dmenu
ffthumb
grid
gridmacro
gridmacro.kde
help
importw
indexer
install-all.sh
install-twily.sh
installng
keep-on
mp3ogg
orage
pipes
pipes.x
pipewire_bt.sh
ports
rain
randwall
rotate.sh
scan.sh
screen-dim
screencast
screencast2
scrot
scrotw
search
skull
slocker
starwars
streamit
sumnum
tty-colorize
usrmount
ytp
ytplay


scriptsbattery-monitor
2 178•  7 years ago•  DownloadRawClose
7 years ago•  2 178

{}
#!/bin/bash
#
# Author:      Twily                    2017
# Description: Battery monitor and notifier
# Requires:    acpi, dunst, notify-send
# Usage:       sh ./battery-monitor & disown
#

NOTIFY=(30 20 15 10 5 4 3 2 1 0)
I=0
F=1
B=1
C=1

while :; do
    ACPI=$(acpi)
    PERCENT=$(echo $ACPI | cut -d' ' -f4 | cut -d'%' -f1)
    STATE=$(echo $ACPI | cut -d' ' -f3 | cut -d',' -f1)
    TIME=$(date +'%T')

    #echo "Battery "$PERCENT"% "$STATE"."

    if [ "$STATE" == "" ] && [ "$B" -eq "1" ]; then
        notify-send -t 0 "ACPI - $TIME" "N/A% Battery Not Found\!"

        B=0
    elif [ "$STATE" != "" ]; then
        if [ "$B" -eq "0" ]; then
            notify-send -t 0 "ACPI - $TIME" $PERCENT"% Battery Found\!"

            B=1
        fi
        if [ "$STATE" == "Discharging" ] && [ "$C" -eq "1" ]; then
                #State change to Discharging
                notify-send -t 0 "ACPI - $TIME" $PERCENT"% "$STATE"\!"

                C=0
        elif [ "$STATE" == "Discharging" ]; then
            if [ "$PERCENT" -eq "${NOTIFY[$I]}" ]; then
                #Discharge warning - low bat
                notify-send -t 0 "ACPI - $TIME" $PERCENT"% "$STATE"\!"

                I=$(($I + 1))
            fi

            F=0
        elif [ "$STATE" == "Charging" ] && [ "$C" -eq "0" ]; then
                #State change to Charing
                notify-send -t 0 "ACPI - $TIME" $PERCENT"% "$STATE"\!"

                C=1
        elif [ "$STATE" == "Charging" ]; then
            F=0
        else
            if [ "$PERCENT" -eq "100" ] && [ "$F" -eq "0" ]; then
                #Charge warning - bat Full
                notify-send -t 0 "ACPI - $TIME" $PERCENT"% "$STATE"\!"

                F=1
            fi

            I=0
        fi
    fi

    sleep 10
done

Top
©twily.info 2013 - 2024
twily at twily dot info



2 017 545 visits
... ^ v