Hack and / - Message for You Sir
It's easy to forget dæmons are there unless they demand your attention. A few years ago, I was walking through the expo floor at OSCON, when I noticed someone in a full BSD dæmon costume getting his picture taken with a few fans. When I saw them trying to figure out how to arrange everyone for the picture I couldn't help but yell, “No! The dæmon is always in the background!”
In case you didn't get the joke, dæmon is a name UNIX people give to processes that run behind the scenes (in the background). Dæmons perform all sorts of useful functions from executing scripts at a certain time (atd and crond) to listening for network connections and spawning the appropriate process to serve the request (inetd). In fact, the d at the end of those scripts stands for dæmon, and you might notice that a number of processes on your system right now end in d.
The whole point of a dæmon is to perform tasks without your intervention or knowledge, but sometimes, it's handy for a dæmon to alert you when a certain condition occurs. On a server, this usually means the dæmon will send an e-mail alert to the administrator, but what about on a desktop? What if you want a dæmon to alert you when you have new e-mail? In that case, it makes more sense for some sort of notice to pop up on your desktop. In this column, I discuss three different methods I use so that dæmons can get my attention on my desktop.
I think the first time I noticed OSD (On-Screen Display) notifications on Linux was with a volume control program. I increased the volume on my computer, and right in the middle of the screen was a volume meter floating above all my other windows, just like on a TV. I instantly was intrigued and had to figure out how they did it. These days, there are a number of different OSD libraries and programs, but my favorite is still osd_cat.
The osd_cat program is a command-line program that displays text sent to it in a pipe. The fact that it accepts piped input makes it ideal for dæmon notification, because it's easy to add to any shell script. This command is part of the xosd-bin package on Debian-based systems, or xosd on Red Hat, and has been around for a number of years.
The simplest way to test osd_cat is to pipe some text to it:
$ echo "Hello World" | osd_cat
If you look at the top left-hand side of your screen, you should see your message appear in a small red font for a few seconds and then disappear. Of course, if you didn't know to look there, you might assume the program is broken because the message is so small. Plus, everyone knows green is the ideal foreground color, so let's spruce up that notification a bit and put it front and center:
$ echo "Hello World" | osd_cat --align=center --pos=bottom ↪--color=green --font=lucidasanstypewriter-bold-24
Ahh, that's more like it, a notification right in the middle of the screen. As you can see, osd_cat accepts a number of options that can control how and where it displays your message. The man page covers all the options in detail, but I highlight the options I used here. The --align argument controls the text alignment much like a word processor and can be set to left (default), center or right. The --pos option controls the Y orientation on the screen and can be set to top (default), middle or bottom. The --color option is self-explanatory, as is --font. If you do want a different font but aren't sure what value to use, just run xlsfonts to see a full list.
In addition to the options I listed, osd_cat has many other options, such as --indent and --offset, that allow you to fine-tune where it displays your text, so you can position it virtually anywhere on the screen. You also can tweak the time the message appears on the screen with the --delay option, and if you plan to pipe multiple lines of text to the screen, be sure to look into the --lines, --age and --wait options, so you can control how osd_cat will scroll multiple lines. There are even --barmode and --percentage options that let you draw a slider bar, much like the OSD volume control I saw.
All of those options are nice, but honestly, I find myself sticking to basic text notifications with osd_cat, and although I have migrated many of my scripts to libnotify, I still like to use osd_cat for audio/video notification, such as when I use a script I wrote to turn on the VGA output on my laptop for presentations. I mentioned this script in my original Lightning Hacks column, but in case you didn't see it, here it is again:
#!/bin/sh if xrandr | grep -q 'VGA connected'; then echo "LVDS + VGA" | osd_cat --shadow=2 --align=center ↪--pos=bottom --color=green --delay=2 ↪--font=lucidasanstypewriter-bold-24 --offset 40 & # choose my laptop screen's resolution by default; # if that fails, try the auto-detected mode xrandr --output VGA --mode 1280x768@60 || xrandr ↪--output VGA --auto else echo "LVDS only" | osd_cat --shadow=2 --align=center ↪--pos=bottom --color=green --delay=2 ↪--font=lucidasanstypewriter-bold-24 --offset 40 & xrandr --output VGA --off & fi
I find it's nice to add visual notifications like this whenever I trigger a script in the background with a keybinding and it's not immediately obvious the script ran, such as in this case, when I'd like to know whether I'm in presentation or regular mode, and it might take the projector a few seconds to respond.
Kyle Rankin is a systems architect; and the author of DevOps Troubleshooting, The Official Ubuntu Server Book, Knoppix Hacks, Knoppix Pocket Reference, Linux Multimedia Hacks, and Ubuntu Hacks.
- You have to be careful there
8 weeks 2 days ago
- Wonder when LJ is going to
8 weeks 3 days ago
- Puerto Rico Free Software
8 weeks 4 days ago
8 weeks 5 days ago
- I hate voice commands
8 weeks 5 days ago
- usabilty --- AGAIN with this nonsense
8 weeks 5 days ago
- Don't make excuses
8 weeks 6 days ago
- Sorry to let you know, but
8 weeks 6 days ago
- Ridiculous statement. Not a
9 weeks 31 min ago
9 weeks 4 hours ago