Dzen: pop-up windows from the command-line

1670

Author: Joe Barr

I stumbled across an interesting and useful tool recently called dzen, a “general purpose messaging and notification program” written by Rob Manea. Basically, dzen provides an instant-on/instant-off pop-up terminal window, along with a multitude of options that allow you to run just about any command.

Dzen has not yet made it into the repositories of most mainstream distros. There are packages for Arch, Gentoo, Sourcemage, and CRUX Linux, and it is awaiting approval for Debian Unstable. If that list doesn’t include your distro, you can install it yourself. Grab the tarball for the latest release from the project’s home page, decompress it, and visit the README file in the resulting subdirectory to see the prerequisites and complete build instructions.

Installation on Ubuntu Feisty Fawn was quick and easy. From within the dzen2-0.5.0 subdirectory, I entered sudo make clean install per the README instructions. That command compiled the utility and placed the executable program in /usr/local/bin, where it became immediately available. If your distro prefers to run programs from a different directory, see the README for information on how to modify config.mk.

While exploring dzen options, I quickly learned how to position, size, and color the terminal window. The -x and -y options function as you would expect, locating the upper left corner of the terminal window on your desktop at position (in pixels) given for the x and y coordinates. Entering dzen2 -x 200 -y 200, for example, resulted in a single burnt-orange (the default color) window, only one line high, starting at that location and extending all the way across the desktop to the right margin.

Adding -w and a number of pixels allows you to limit the width of the window. The -l option sets the number of lines. A complete command looks like the one below:

dzen2 -x 200 -y 200 -w 600 -l 10

At first, nothing seemed to have changed after I added the -l option, but when I moved the cursor over the dzen2 window, it immediately expanded to 10 lines. The window collapsed to a single line again when the cursor moved away, just as empty as when it was created. A right-click while the window has the focus closes it and terminates dzen.

Next, I modified one of the examples in the README file to display a monthly calendar in its own small window for 20 seconds, then disappear. The example command looks like this:

(echo Header; cal; sleep 20) | dzen2 -l 8

I modified the command slightly to position and color the window, then added it as an alias by inserting it into my ~/.bashrc file in a line that looks like this:

alias day='(echo Today; cal; sleep 20) | dzen2 -x 200 -y 200 -w 200 -bg blue -l 8′

When I enter the day command, the desired window appears on my desktop and remains there for 20 seconds. See Figure 1 for an example.

To get fancier, I started again with an example from the README. This one shows a monthly calendar populated with notes from the remind program. Remind is not part of the default Ubuntu install, but it’s easy enough to install it with apt-get. To make it more interesting, I set it up as a shell script to be executed whenever I press the Meta and p keys simultaneously.

The original command looked like this:

(echo Monthly Schedule; remind -c1 -m) | dzen2 -l 52 -w 410 -p -fn lime -bg ‘#e0e8ea’ -fg black -x 635

I changed the number of lines to 26, the width to 610, and removed the lime font argument. I called my script schedule.sh, and made it executable with chmod +x schedule.sh. It is very simple, and looks like this:

#!/bin/sh
(echo Monthly Schedule; remind -c1 -m) | dzen2 -l 26 -w 610 -p -bg '#e0e8ea' -fg black -x 635

Setting up a new hot key is easy in GNOME. After starting the gconf-editor program, I selected Apps -> Metacity -> keybinding_commands -> global_keybindings -> run_command_1, and used p for the binding, so that whenever I press the Meta (a.k.a. the Super key) key, command_1 is executed. I then needed to select keybinding_commands instead of global_keybindings and add “schedule.sh” as the command to be executed. Nothing to it.

Now, when I press Meta-p, my monthly schedule pops up. Because 26 lines is not enough to hold the entire calendar, the window becomes scrollable, allowing me to browse it using the up and down arrows. It remains on the desktop until I close it with a right-click of the mouse.

Dzen is more interesting than useful, at least for me, but it is interesting enough so that I will watch its development and be on the lookout for new ways to take advantage of its abilities.

Categories:

  • Tools & Utilities
  • Desktop Software