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
Code: Select all
notify-send "Battery $(battstat)"
Code: Select all
* * * * * /usr/local/bin/battcheck.sh
Code: Select all
#!/bin/sh
[[ $(battstat -c) < "10" ]] && aplay /usr/share/sounds/alsa/Noise.wav # or notify-send "Warning, battery low"