~scripts
40 itemsDownload ./*


..
dzen2
tiling
vosh
4cdl
4trips
alarm
ambient
battery-monitor
checkit
cleverbot.py
clock
color-gen
colors-hex
compton
dailywall
dmenu
importw
indexer
keep-on
mp3ogg
orage
pipes
pipes.x
rain
randwall
screen-dim
screencast
screencast2
scrot
scrotw
search
skull
slocker
starwars
streamit
sumnum
tty-colorize
usrmount
ytp
ytplay


scriptsbattery-monitor
8 months agoDownloadRawClose


#!/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 at openmailbox dot org
©twily.info 2013 - 2017



744 045 visits
... ^ v