battstat - yet another battery status

Submitted scripts and programs
Forum rules
Your own work only.
machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

battstat - yet another battery status

Unread post by machinebacon » Mon Jan 18, 2016 10:07 pm

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"
..gnutella..

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: battstat - yet another battery status

Unread post by rhowaldt » Tue Jan 19, 2016 3:19 pm

great, love it, nice and simple, very useful - thanks!
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

Post Reply