tPopup a battery notification, all the time - scripts - various script and utils
(HTM) git clone git://z3bra.org/scripts
(DIR) Log
(DIR) Files
(DIR) Refs
---
(DIR) commit 5752ad6c29a72b62dce8463308069026b4390546
(DIR) parent 8c70f909f342b654879eb7282cac478a67dc7112
(HTM) Author: z3bra <willy@mailoo.org>
Date: Wed, 19 Mar 2014 11:54:09 +0100
Popup a battery notification, all the time
Diffstat:
M battery.sh | 43 +++++++++++++++++++++++++------
1 file changed, 35 insertions(+), 8 deletions(-)
---
(DIR) diff --git a/battery.sh b/battery.sh
t@@ -1,17 +1,44 @@
#!/bin/sh
#
-# Beep once when under 15%, twice under 10, and three times under 5%
-# Under 3%, you're asked to shutdown
+# beep once per level. does not beep when charging
+# get battery level and status (charging or not)
BATC=`cat /sys/class/power_supply/BAT1/capacity`
BATS=`cat /sys/class/power_supply/BAT1/status`
+# Run this if sound is enabled
+BELL_SOUND="beep -f1000 -l200 -D50"
+
+# and this in case of no sound enabled
+BELL_VISUAL="$HOME/bin/popup battery $BATC%"
+
+usage () {
+ echo "usage: `basename $0` [<low> <critical> <dead>]"
+ exit 1
+}
+
+level () {
+ echo $BATC%
+ exit 0
+}
+
+# check wether speakers are on or not
+amixer get Master| grep -o '\[on\]'>/dev/null
+SOUND=$?
+
+# If no argurments, return battery level
+test "$#" -eq 0 && level
+
+# if less than 3 args, learn how to use, dumb
+test "$#" -lt 3 && usage
+
+# if battery is charging, do not alert user
test "$BATS" == "Charging" && exit
-if test $BATC -gt 3; then
- test $BATC -lt 15 && beep -f1000 -l200 -D50
- test $BATC -lt 10 && beep -f1000 -l200 -D50
- test $BATC -lt 5 && beep -f1000 -l200 -D50
-else
- test $BATC -lt 3 && espeak 'Battery is empty, please shut down'
+if test $SOUND -eq 0; then
+ test $BATC -lt $1 && $BELL_SOUND # one bip for level <low>
+ test $BATC -lt $2 && $BELL_SOUND # two bip for level <critical>
+ test $BATC -lt $3 && $BELL_SOUND # battery is <dead>, bip 3 times
fi
+
+test $BATC -lt $1 && $BELL_VISUAL # popup a notification under <low> level