A battery alert program that sends a notification when the battery percentage reaches a certain level. This is a modified bash script, originally written by Eric Murphy. The batterynotify
script should be added to the PATH
in order to enable custom battery threshold configuration from the terminal.
It was only tested on EndeavourOS with GNOME desktop environment, but the script should function on any other distro.
There are 2 notifications: when the battery is low and when it is full.
By default, it alerts the user when the battery reaches 30%
or 80%
. We can edit both thresholds by calling the script with the proper flags:
Flag | Description |
---|---|
-l | Adjust the low battery warning threshold |
-f | Adjust the full battery warning threshold |
For example, to get notifications when the battery reaches 25%
and 70%
:
batterynotify -l 25 -f 70
-
Install the dependencies
-
Change the value of
DBUS_SESSION_BUS_ADDRESS
in the script to the output of the following command (without the guid):echo $DBUS_SESSION_BUS_ADDRESS
-
Optional! The file where the threshold values are saved can be changed, by editing the value of
VALUES_FILE
in the script. -
Give executable permission to the script and add it to the PATH:
cp batterynotify /usr/bin/
-
Set the script as a cron job, by running the
crontab -e
command. Paste the following line to the file:*/3 * * * * /usr/bin/batterynotify
and save it. The 3 means that the script will be executed in every 3 minute. Adjust it to your needs if it is too frequent.On Arch based systems the
cronie.service
needs to be enabled:systemctl enable cronie.service systemctl start cronie.service
-
On GNOME, to run the script on startup too, the
batterynotify.desktop
file must be copied to~/.config/autostart
:cp batterynotify.desktop ~/.config/autostart