Page 1 of 1

battstat - yet another battery status

Posted: Mon Jan 18, 2016 10:07 pm
by machinebacon
Largely inspired by https://github.com/dkeg/inspin/blob/master/promptd

I just wanted a plain text output for any battery (BAT0 or BAT1) that can be piped to dunst or xosd or read by any other application. Nothing magical about this script, just thought I'd share. Modify as you wish.

Code: Select all

#!/bin/bash

BATT=$(find /sys/class/power_supply/ | grep BAT)
CAPS=$(cat $BATT/capacity)
STAT=$(cat $BATT/status)

usage(){
    echo "$0: print battery capacity and status"
    echo "	$0 -c print capacity"
    echo "	$0 -s print status"
}

[[ $1 = "-h" ]] && usage && exit 0
[[ $1 = "-c" ]] && echo $CAPS && exit 0
[[ $1 = "-s" ]] && echo $STAT && exit 0
[[ $1 = "" ]] && echo $STAT $CAPS && exit 0
pipe to libnotify:

Code: Select all

notify-send "Battery $(battstat)"
crontab entry, check every minute:

Code: Select all

* * * * * /usr/local/bin/battcheck.sh
battcheck.sh example

Code: Select all

#!/bin/sh
[[ $(battstat -c) < "10" ]] && aplay /usr/share/sounds/alsa/Noise.wav # or notify-send "Warning, battery low"

Re: battstat - yet another battery status

Posted: Tue Jan 19, 2016 3:19 pm
by rhowaldt
great, love it, nice and simple, very useful - thanks!