-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbattNotification.sh
executable file
·53 lines (45 loc) · 1.13 KB
/
battNotification.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
#
#
depCheck(){
# Checks if a piece of software exists on a system and
# if it doesn't, stops execution and exits with an error.
#
# Arguments:
# $1: a command to test
#
if [ ! `command -v $1` ]; then
echo "You need $1 installed to use this script, exiting..."
exit 1
fi
}
notify(){
# Provides a common way for the script to send notifications
# to the user in the console and in the gui.
#
status="`acpi`"
echo "$activity"
echo "$status"
export DISPLAY=:0.0 && notify-send \
-i /usr/share/icons/gnome/scalable/status/battery-good-symbolic.svg "$activity" "$status"
}
depCheck acpi
show="n"
percent=`acpi | cut -d"," -f2 | cut -c 2-4 | sed -e s/'%'//g`
# If we're automatically running the script
# let's not spam the user, only tell them if
# there is a reason or if no arguments
case $1 in
"auto")
if [ $percent -lt 25 ]; then show="y"; fi
;;
"")
show="y"
;;
esac
if [ "$show" = "y" ]; then
activity="Battery Status"
if [ $percent -lt 25 ]; then activity="Battery under 25%"; fi
if [ $percent -lt 20 ]; then activity="BATTERY LOW"; fi
notify
fi