~scripts
58 itemsDownload ./*

58 itemsDownload ./*

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


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

{}
#!/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 160 668 visits
... ^ v