Using Bash to Pop-up custom Notification in Linux

0
1878
Using Bash to Pop-up custom Notification in Linux

Bash Scripting Tutorial : 2

In today’s tutorial, we are using bash to pop up custom notification in linux and see notify-send command and its amazing uses.

Today we are going to pop up a small notification window in every one or two minutes to get updates about sites or scores or any other stuffs that matters to you. Notify-send command is useful if you’re busy doing stuffs and can’t manage time to search about other important updates on scores (ex – games) or reminders. While you do your other stuffs you can still see the updated score or updates from any site you want without hampering your important work that you’re doing. To overcome that issue you can make use of notify send command to automatically receive the specific updates in a popup window as a notification in your computer screen so that you can keep track of them with out any hassle.

So let’s get into it. First and foremost, install following tools into your computer system :

lynx

Lynx is a command line web browser which basically runs on all platform. It consists of great features like highlighting the chosen link using your mouse or typing the number assigned to each links.

You can check other cool tools in this article.

notify-send

According to its man page, it is a program to send desktop notification, inform the user about an event of displaying some form of information without getting in the user’s way. Its syntax is :

So let’s get right into the topic. First of all you need to open your web browser and find the information that you need to check every few minutes or may be seconds. Once you find the field where the information is located then copy the url link and go to you terminal and type :

This will dump everything that’s in that link into your terminal window. Now find out the information from the terminal that you needed and copy a line before the actual content and type :

The above command will only dump the lines that comes after the line that you copied and put in -e option. It will also display only till the number of lines that you specified with -A option. Here is the example :

Here the tail command is used to display the last 8 lines from the Trending Now line and its helpful if there is a big space in between the main context and the closest line to that context.

So now we need to display the popup that we can see in our system and find out if any new articles have been added to the site. So inorder to do that we are going to use a command called notify-send. This command is installed by default. If not, type :

Now, let’s get the pop up notification :

Once you hit enter, notify-send will pop up everything that was previously displayed in the terminal as a notification in your system, so that you can see it from any window you will be currently in.

So now to make the notification keep looping and displaying the updates in certain interval of time, we can use while command. Type :

Now when you hit enter, it will pop up the notification every 1 minutes with the updated results, because it downloads the content every time notification pops up and keeps looping this until you terminate the script.

For our convenience, let’s make a script and drop all that command into it and then just execute the script instead of typing the command each time to get the updates. So let’s make a file called popup.sh and put the command in following way :

That’s it. Now provide the execution permission to the file popup.sh.

Now execute it,

It will start poping up the notification every 1 minutes with updated contents. To terminate the file just press ctrl+z and if you want the script to run in background, type :

Above command will run our script in the background. If you want to terminate the script then type :

Find the process id (PID) of your script and type ;

If it didnt work then, type :

And find the PID of nohup and kill it :

That’s it. Now it will terminate the background process of popup.sh.

That’s all in this article. Hope you found it useful. Support us and stay tuned for more updates. Happy scripting!!

LEAVE A REPLY