Dawit-Sh / Notify-Me

A simple bash script i made to notify the user when the battery percent has reached 40%.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Notify Me

A 6.8kb Script to Notify you about your battery.

Built with ❤︎ by Dawit-Sh

Table of Contents

How to use

This is a small shell script i created to notify the user to charge their pc when the battery % reaches 40%. So how do you use the script

Clone the repository

$ git clone https://github.com/Dawit-Sh/Notify-Me.git

Set the Script Executable

$ chmod +x NotifyMe.sh

Run the Script

$ ./NotifyMe.sh

Dunst

Now for people using i3 and other WM's might find it hard to push notification throught notify-send because for most of the time Dunst is the daemon running notification service. So there are a few fixes

try installing notify-os

$ sudo <your-package-manager> install notify-osd

if this method does not work then we will have to do a bit of text editing.

sending push notification using Dunst

$ dunstify "Hello World!!" -u critical -h 10

if inputting this message to your terminal sends out a notification that stays on for 10s, then we are good to go. Using your favorite text editor (nano, vim, nvim, vscode) open the NotifyMe.sh

when you open the code it will look like this now i am using my favorite editor Vim NotifyMe.sh

So now in the bash script we will edit a few lines:

>  notify-send -t 10000 -u critical "Battery level low" "Your battery level is low. Please plug in your charger. $USER"; speaker-test -t sine -f 1000 -l 1 & sleep .9 && kill -9 $!

We will replace the notify-send -t 10000 -u critical "Battery level low" "Your battery level is low. Please plug in your charger. $USER"; speaker-test -t sine -f 1000 -l 1 & sleep .9 && kill -9 $! with dunstify "Battery level low, Please plug in your charger. $USER" -u critical -h 10 So the code will look like this

> dunstify "Battery level low, Please plug in your charger. $USER" -u critical -h 10; speaker-test -t sine -f 1000 -l 1 & sleep .9 && kill -9 $!

NotifyMe.sh Edited

save and run the script ./NotifyMe.sh

Systemd

Now always running the script is going to be tiring and annoying so we should set up systemd to run it, for those who do not use systemd check out the Cron tab section mean while for those using systemd let us setup a systemd service.

You could create a file (as sudo) with you favorite editor (nano, vim etc) like:

$ sudo vim /etc/systemd/system/NotifyMe.service

It should contain at least the following:

[Unit]
Description=start NotifyMe

[Service]
Type=simple
ExecStart=/path/to/NotifyMe script

[Install]
WantedBy=multi-user.target

To ensure that the service will start after reboot execute:

$ sudo systemctl enable NotifyMe.service

You can check it any time using

$ journalctl -u NotifyMe.service

Cron tab

To create a crontab file, use the

$ crontab -e

This command will open the crontab file in your default text editor. Once the file is open, you can add the command:

@reboot /path/to/NotifyMe.sh

Once you have created the crontab file, you can save it and exit the text editor.
Now, the bash script will run on bootup and stop on shutdown.

Here are some additional things to keep in mind:

  • The @reboot keyword tells cron to run the job once, at startup.
  • The /path/to/NotifyMe.sh is the path to the bash script that you want to run.
  • You can use other keywords in the crontab file to specify when the job should run. For more information, you can refer to the crontab man page: https://linux.die.net/man/5/crontab

Credits

Building this script was not easy as i had to research some commands so here are some of the resources i used

License

GNU General Public License v3.0

About

A simple bash script i made to notify the user when the battery percent has reached 40%.

License:GNU General Public License v3.0


Languages

Language:Shell 100.0%