Wallpaper & System Info Management Script

I’ve been working on my little wallpaper management bash shell script that handles changing wallpapers on my desktop. The image to the right shows the system information that is displayed down the right edge of my screen. From the top you have:

Left edge of my desktop
Click for larger view

  • Local weather forecast for the next four days.

  • The current and next calendar months.

  • List of the last twelve incoming phone calls.

  • Various system info such as cpu usage, disk space and top five processes.

(The image contains bogus phone numbers, don’t bother trying to ring ’em.)

Ever since I upgraded my desktop to two monitors this background information has been a lot more visible off to the side, and so I decided to give it a bit of an update.

Originally I was using conky to display all that information, but all the info aside from the system info is fairly static, and could easily be updated when the wallpaper changes every five minutes, instead of being a set of conky processes, so I’ve been playing a lot with ImageMagick and sharpening up my bash scripting skills to actually write the information onto the wallpaper image. So far I have the phone log and calendar being written, and plan to do the weather forecast next, so then I will only be running one conky process.

Currently the script does the following:

  • Check if the screen saver is active. If so, then skip the whole thing and check again in five minutes as the computer isn’t being used at the moment.

  • Randomly pick an image file from my wallpapers folder to use for the desktop. It will cycle through the complete set of available images before repeating.

  • Takes a look at the aspect ratio of the image to figure out if it is suitable for a single screen or dual screen background.

    • If only single screen, finds another single screen image to use and stitches the two together side by side.

    • Resize the whole thing to be the same dimension as my desktop (width of both screens).

  • Apply the watermark image, which is what gives you the translucent grey rectangles behind each of the four bits of info.

  • Write the calendar and phone log information into the image.

  • Chuck the completed image up as the desktop wallpaper.

  • Wait five minutes and repeat.

So far, so good. I’ll write the weather info into the image next [DONE!]. At some point I want to update the weather script to pull the information from the XML files published by the Australian Bureau of Meteorology instead of getting it from weather.com as they always seem to be a degree or two out, and presumabley the ABoM would be more accurate [Also done!].

I’m also gonna display some quota usage metrics for my ISP. They provide an API for account holders to retrieve various info about their data usage, so at some point soon I’ll write some scripts to retrieve and format the info. UPDATE 2010/1/25: Done! I’ve updated the image to show what it looks like. It’s down next to the conky display. (Note that I’m not really spam limited, just a simulation for the demo, honest!)

Might also run another conky process to tail the last few lines of /var/log/messages. [UPDATE: I’m actually using the KDE/Plasma File Watcher widget to do this, but I added another background rectangle for it to the watermark file. You can see the right edge of it next to the weather info in the updated image above.]

And in my more nuttier moments I’ve contemplated overlaying images from The Human Clock® and/or Calendar. Pity there isn’t an API. Hmmm, maybe I better stick to what I’ve got…

At some point I may publish the bash script and ancillary bits and pieces for other people to use if interested. Will probably need a bit of a tidy up and some guide lines for hacking written up first. Also, sometime in the next month I will be upgrading from openSUSE 11.1 to 11.2 and going from KDE3.5 to 4.3 in the process, so the script will need a small amount of attention at that point.

UPDATE: Actually, it needed a lot of attention to get working under KDE 4. One of the differences from KDE 3.5 is that you set the wallpaper for each monitor separately (even though you use it like one big desktop). Also, there are no dbus or other convenient methods to tell Plasma to use a particular image as the wallpaper.

In the end I made the following changes to the script:

  • Prepare the images for the left and right monitors separately, and only stitch them together at the very end if we are running KDE 3. For dual-screen wallpapers, crop the left and right parts into separate images.

  • It now caches the correctly resized image(s) for the wallpapers. This saves a little bit of processing and also having to figure out if it is a dual-screen wallpaper if we have already seen the image before. (Each time the script starts it’ll clear the cache of files older than two days, just to help with clearing out stale files - really the overhead of this part of the processing is pretty small.)

  • Do all the watermarking and textual processing on the right image only.

  • Finally, once the images are ready, move them to their final folder location – effectively being close to an atomic operation. I’ll explain why that is important below.

The bugbear though is, once I’ve got these images ready, how do I set the desktop in KDE 4? I’ve lodged a bug report for a dbus command to be added to allow you to do this, but in the meantime I’m using a plasma plugin that can run a script on a specified time interval for each monitor, and set the wallpaper to whatever image path the script returns.

At the moment, I just pointed them to simple one-liner scripts that return the paths where by background manager script places the prepared files, and does this every 30 seconds. This is why I need the final operation to be fairly atomic - moving the completed file into place - rather than say having the output of the last ImageMagick operation write to the final location. The desktop could try and read the file while it is still being written - this way the chances of that happening are minimised.