22 July 2007
Prediction is difficult …
… especially of the future! This fact of life has to be a daily nuisance to meteorologists all over the planet as they struggle to interpret satellite images of the Earth’s atmosphere painted in all colors of the spectrum. Meteorology is a science of probabilities, a trade whose precision diminishes rapidly the farther into the future predictions are made. Tomorrow’s weather can almost always be predicted with certainty, but what about today’s?
InAccuWeather
The OS X Dashboard sports an “Accuweather Widget”, which, although extremely slick in its look and feel, fails miserably at displaying even the current weather situation. At least in Denmark. Today on July 22nd 2007 AD the Danish Meteorological Institute (DMI) informs anyone who shows an interest that it is raining. In fact it will rain so much here that the institute has issued a warning for “extreme weather conditions” with 17°C and yet AccuWeather thinks that we have a cloudless sunshine here and 27°C!!
Did anyone say “useless”??
What to do? I decided to ditch AccuWeather and write a widget that grabs the current 5 day forecast image from DMI. The result can be seen in the picture below with AccuWeather gleaming sunshine on a rainy Sunday:

The image caching nightmare
Writing a widget is not rocket science, and requires little more than HTML and Javascript skills in its most basic form. The Dashboard is basically a specialized web browser. Brilliant! Unfortunately this also means that widgets inherit any problems that browser applications suffer. One of these problems relate to the caching of images. In this case, the forecast, which DMI has decided to publish on the same image URL. The current 5 day forecast for Eastern Jutland, for instance, is always published on http://www.dmi.dk/dmi/200611090030_cms6dognostjylland.jpg”. Once the Dashboard has downloaded this image, it will be cached for the lifetime of the widget i.e. until it is eventually removed, and so the forecast slowly but surely becomes irrelevant.
I spent the better part of an afternoon scouring the web for solutions to this annoying problem and ran in to numerous frustrated Javascript developers. After pondering the problem some more I came up with the following possible solutions:
- Delete the widget cache. The Dashboard cache lives under ~/Library/Caches/DashboardClient and can be removed by a user with root privileges without problems. In theory this solves the problem, but alas the Dashboard will have to be restarted for the cache to be reread. No go.
- Write an applet that gets the image. I was hoping a Java or a Flash Applet could do the trick, but these are limited to their sandboxes and can generally not access the HTML DOM of their enclosing document.
- Make a server side PHP image proxy. This site, Vaportrail, has PHP support and I wrote a simple script to proxy the image from DMI. While this solution works, it means lots of irrelevant traffic on my site and hence load. Not the best solution.
- Leverage the fact that widgets have extensions for calling shell scripts. A bash script could use CURL to get the image, write it to /tmp/ with a name made unique by the current date, and the widget could load it from the local folder. Eureka!
Caveat: While my solution works, it will fill /tmp/ with images: one per day per region you choose to display. I could have implemented a cleanup facility in the shell script as well, but I am not a big fan of scripts that perform “rm” on my local folders. I leave that as an exercise for those with strong stomachs.
The widget can be downloaded from this link. Quote Apple: “Mac OS X v.10.4 Tiger is required. If you’re using Safari, click the download link. When the widget download is complete, the widget installer appears. Click Install if you want the widget installed on your Mac. If you’re using a browser other than Safari, click the download link. When the widget download is complete, unarchive and open it to show the widget installer.”
Enjoy! And have a sunny summer …

