by Paul Arnote (parnote)
I have to be completely honest about something. I love messing around with bash scripts. They play right into my quest to solve problems and save time. It also harkens back to my days when I was a burgeoning shareware programmer that started way back when I was using Windows 3.1. Trust me … I didn’t get rich off of the shareware I wrote (not even close).
With my bash scripts, I’m able to accomplish repetitive tasks with a minimum of effort. One example is the bash script that I wrote (and use monthly) to create the various sized images used for the magazine’s HTML layout. And I have not one, but two versions of that script. One creates the various sized JPG files from the PNG file produced by Scribus. The other creates a PNG file from the actual PDF, and then I run the other script on that PNG file to create the various sized JPG files.
I have well over a dozen bash scripts that I use as the “motor” for quite a few Thunar Custom Actions. I’ve featured most of them here in the pages of this magazine, in fact. Many of my bash scripts have GUI elements to prompt for input, or to display the progress of the task being handled. And, to be quite frank about it, I tend to use Zenity over yad a LOT more often to handle/display those GUI elements, probably mostly out of my increased familiarity with Zenity. I should probably try to use yad more, because it has a LOT more options and capabilities than Zenity. Kdialog (the third set of GUI elements available in the PCLinuxOS repository for use from a bash script, from the KDE developers) has a set of instructions/commands that's even more sparse than Zenity, and a whole different usage format, as well.
I’m definitely not a command line commando, nor am I a bash warrior. But there is a great sense of accomplishment to streamline several tedious and mundane tasks into one bash script. I definitely have a LOT more to learn when it comes to both (the command line and bash scripting). I just look at it as a work-in-progress. For example, I’m super weak in my understanding of how to properly use sed or awk. Eventually, I’ll get it.

Image by Gerd Altmann from Pixabay
One of the things I’ve been pursuing with my bash scripting is how to create an interactive script that runs in the notification tray of my Xfce panel. I’m not just talking about displaying text in a notification popup. Any eight-year-old can do that with one simple command. I mean something you can truly interact with. Up to this point, it has become my bash scripting “holy grail.”
For the longest time, I thought that was virtually impossible, without having to write a full program in C, and all of the things that go along with that whole process. I felt like there certainly had to be a way to do so from a bash script.
I searched for YEARS to figure out how to do this. And, I was blown away by how simple it actually is. You won’t believe this, but it’s literally a one-liner bash script. I found it hard to believe, too.
This script places a launcher in the notification tray of your panel. Sure, I could have just created another launcher for this on my panel, but what’s the fun of that? Anyone can do that. This is a “proof of concept” thing for me.
While I’m not a “gamer,” I do like to play a few games. Not only does it help keep my mind active in retirement, but it also provides a nice diversion from magazine duties. Playing the games also helps me overcome writer’s block, a visitor who visits way too often.
So, my launcher contains five games that I like to play to pass time. You could, however, have whatever programs you want in this launcher. If there are programs you routinely use and that you want frequent or easy access to, those are definitely candidates for inclusion in your notification area launcher.

Image by OpenClipart-Vectors from Pixabay
So, here’s my bash script, which I call “game-launcher.sh.” The entire script is only 333 bytes long. It’s short enough that I’m NOT providing a download for it. Typing it in should take you all of five minutes or less in a plain text editor. (That means NOT LO-Writer, or any other word processing program).
#!/bin/bash
yad --notification \
--image="applications-games" \
--text="My Fav Games" \
--menu="PySol!pysol!pysol
|GMahjongg!gnome-mahjongg!gnome-mahjongg
|Gweled!gweled!gweled
|Peg-E!peg-e!peg-e
|Space Cadet Pinball!flatpak run com.github.k4zmu2a.spacecadetpinball!pinball
|Quit!quit!gtk-quit" \
--command="menu"
The “space” and “backslash” at the end of the command parameters makes it easier to read (and edit). If you want to list it all out on one line, it would look something like this:
#!/bin/bash
yad --notification --image="applications-games" --text="My Fav Games" --menu="PySol!pysol!pysol|GMahjongg!gnome-mahjongg!gnome-mahjongg|Gweled!gweled!gweled
|Peg-E!peg-e!peg-e|Space Cadet Pinball!flatpak run com.github.k4zmu2a.spacecadetpinball!pinball|Quit!quit!gtk-quit" --command="menu"
As you can see from reading the bash code, my launcher lists PySol, GMahjongg, Gweled, Peg-E, and a flatpak of Space Cadet Pinball.
So, let’s walk through the code, step-by-step. Of course, it starts off with the typical bash shebang (#!/bin/bash). Next, we call on “yad.” Yad (which stands for Yet Another Dialog) is responsible for allowing us to have an interactive presence in the notification area with a bash script.
The first parameter is “--notification.” This allows us to place what follows in the notification area. The second parameter, “--image,” tells yad what icon to use as the icon in the notification area. The third parameter, “--text,” defines the text that will appear in the popup that is displayed when we hover the mouse cursor over the icon.
The fourth parameter is where all the “magic” occurs. The “--menu” parameter defines the menu that appears when we right-click on the icon in the notification area. Each menu item is split up into three parts. For the first one, PySol, the first part is the name that appears in the menu. The second part is the name of the executable to launch. The third part is the icon to use to represent your menu item in the menu. Each part is separated by an exclamation mark.
A “pipe” character (“|”) separates each entry in the menu. So, you can put as few or as many items into the menu as you like. The last entry in the menu is “Quit,” which allows you to exit the launcher.
Thus, each menu entry should follow this format: [MenuText]![ExecutableName]![IconToUse]. That's for the first menu item. Each subsequent menu item will start with the “pipe” character, “|”, followed by the format specified for the first menu item.
The final part of the yad command is “--command=”menu.”” This allows you to choose and launch the item you select. Below is an image of what it looks like on my computer.

You will notice that each icon in the menu is a green raindrop, with the exception of the last item, “Quit.” No matter what icon I specify, I still only get the green raindrop as the icon. Still, we specify it, because yad is expecting to find all three parts to the menu entry … the text to display in the menu, the executable name, and the icon to use. For me, this is a minor annoyance, but one I can live with. After all, my goal was to make an interactive item in the notification area from a bash script. Even with that small niggle, I feel like it’s a success.
I have my script set up to launch automatically every time I log into Xfce. While I haven’t tested it on any other desktop, there’s no reason this script *won’t* work on other desktop environments.
Summary
So, now that I’ve tackled my “holy grail” of bash scripting, I’m left wondering if this information can be leveraged to do more. THAT is now my new quest. I’d LOVE to be able to create something akin to Xfce’s KbLEDPlugin that will tell me when one of the “lock” keys (CapsLock, NumLock, ScrollLock) is activated, from something as lightweight and easy as a bash script. We’ll see, but I’m not holding my breath. But who knows what may happen, or where/when the next element of inspiration might drop into my lap.
Using this script saves me from digging through my PCLinuxOS menu to launch the games I want to play, when I want to play them. It’s just a simple right click on the icon in my notification tray, and then select the program I want to run with a left click of my mouse. Like I mentioned earlier, you can put any programs you want quick access to in your menu. It doesn’t have to be games. I just chose my favorite games to be in my menu selections.
|