Alternative root-tail on your desktop

[ Thursday, 24 April 2008, michalrz ]

Sometimes, while working with a computer one may find it useful to view the content of a certain file, like a system log, or a report of a longer process. Sometimes, however, one might wish to be spared the constant switching to the console and typing cat; it would be best if the content of a necessary file could be integrated into the desktop.

Dragonia Magazine

A solution to this problem came a couple of years ago with the application root-tail. With an exemplary command:

root-tail -g 620x200+0+520 -wordwrap -color grey \
/var/log/daemon.log &

the application checked the content of the particular file in real time and printed its final lines in the specified area of X “root-window”, available independently of the running window manager. For KDE it might be necessary to turn on “Allow programs in desktop window” in the tab Desktop>Behavior in KDE’s control center.

Unfortunately, in some cases (depending on X and KDE versions) root-tail may run incorrectly: the text may disappear once in a while and reappear only after refreshing the desktop (e.g. after moving a window). Moving desktop icons in KDE may also interfere with root-tail.

It is a good excuse to get a grip on the DCOP interface in KDE and other popular free tools and create a simple script, which could go further than root-tail and set a new wallpaper at regular time intervals. This wallpaper would contain the desired text as an image. Let’s see what it takes to accomplish the above task.


DCOP stands for Desktop Communication Protocol — a protocol allowing communication between processes and program components. It allows one to control various applications as if with a remote control, running procedures predefined by the programmers. Running bare dcop in the console will list programs with defined DCOP interfaces. We’ll use this trick to get the path to the currently set wallpaper and to set the image with text superimposed as the new wallpaper.

Imagemagick package

This set of programs for manipulating images will be necessary to superimpose the content of a text file on the image wallpaper. The result of our work may be placed somewhere in the /tmp directory. The use of the components of this package — convert and mogrify — has already been described in one of the previous issues of Dragonia Magazine. So it’s enough to remind you that superimposing text on an image can be accomplished by running:
convert -font helvetica -pointsize 15 -draw "text 10, 10 'Any text'" photo.jpg photo-2.jpg
The text to be superimposed we will obtain by running tail, which will return the last N lines of a file passed as an argument. We will also need…

Some bash tricks

… in particular, obtaining the font size of the taskbar (to use it for the desired text) with grep and cut. In this particular example this will be:
FONT_SIZE='grep -i taskbarfont ~/.kderc | cut -d ',' -f 2'
Generally, the script shown here will do the following:

  1. Setting variables — position of the displayed text, font size, filename of the current wallpaper…
  2. Infinite while loop, executing the following:
    • running convert on the current wallpaper, drawing the output of:
      tail -n 20 $FILE
      Convert might not like obtaining too many lines, in which case we should decrease the value of “n”.
    • Setting the newly created file as a wallpaper.
    • Waiting a fixed amount of time before refreshing.

…and a simple script

Below is an example script, displaying on the wallpaper the last 20 lines of kernel.log every 30 seconds:

# how many pixels to leave from the left and from the top,
# before we start to write
# here select the file to be observed
# obtaining font size,
# here you can put a fixed value, like 14
FONT_SIZE='grep -i taskbarfont ~/.kderc | cut -d ',' -f 2'
#running dcop to get the path of the current wallpaper
WALLPAPER='dcop kdesktop KBackgroundIface currentWallpaper 1'

# infinite while loop (we terminate it by killing the process)
while [ 1~]; do
    # wallpaper conversion -- adding on top the
    # last 20 lines of the observed file
    convert -font helvetica -pointsize $FONT_SIZE \
    -draw "text $OFSET_X,$OFSET_Y ''tail -n 20 $FILE''" \
    $WALLPAPER /tmp/wallpaper.png
    # we must copy the newly created wallpaper to another file
    # to avoid trouble while switching virtual desktops
    # during the conversion (to prevent KDE from setting
    # the improper file as wallpaper)
    cp /tmp/wallpaper.png /tmp/wallpaper2.png
    # setting the prepared image as wallpaper
    dcop kdesktop KBackgroundIface setWallpaper "/tmp/wallpaper2.png" 1
    # wait 30 seconds
    sleep 30

Before running the program again it’s good to set the “clean” wallpaper, or else the script will display the text on an already modified image.

It should be mentioned that it’s not the most CPU-efficient solution. Frequent launching of convert consumes much CPU time (on the author’s system each call took about 6 seconds) and may not be the best solution for machines already loaded with work or equipped with an aging CPU (testing on a 2.4 GHz Athlon 64 went smooth).

In case we don’t want our machine involved too much in drawing the wallpaper, we might try to run the script with a lower priority:

nice 10

The script with execution bit set may be placed, for instance, in the autostart directory of KDE (/home/user/.kde/Autostart).

Figure 1. Our solution in action, viewing events from kernel.log


  1. – home page of one of the “true” root-tail versions.

About the Author

Michał Rzepka

Dragonia Magazine editor, proofreader, translator. KateOS user.

New AdTaily ads!

Are you a film buff?

film buffs community, movie recommendations and reviews

RSS: Comments

You can follow the comments to this article through a special channel RSS 2.0 .

Related articles: CLI

 more »

PolishLinux Top Content

Become our fan on Facebook! on Facebook

Follow PolishLinux on Twitter!

Follow polishlinux on Twitter

Google Ads