View Doppler radar-in-motion on the desktop

Jun 12, '08 07:30:00AM

Contributed by: jvajda

This hint explains how to view an in-motion Doppler weather radar image from The Weather Channel on your desktop. A little precaution is in order, though: this will eat up quite a bit of CPU cycles (between 12% and 30% on an Intel Mac mini). I use it on a machine that does monitoring/notification, but I'd never use it on a machine I use for normal work. The "animation" is somewhat slow, but tolerable in my opinion. This hint requires use of the command line. Also, I make no guarantees that it won't break something, etc. I've only done this on Leopard, but I can't see any reason why it wouldn't work with Tiger (no Panther or earlier, because they don't have launchd).

There are two components to this: A unix script to retrieve the images from The Weather Channel or NOAA or wherever else, and a launchd agent that periodically runs the script. Here's the shell script:

#!/bin/sh

if [ ! -d ~/Library/WeatherMaps ]; then
mkdir ~/Library/WeatherMaps
fi

curl -s http://image.weather.com/looper/archive/us_ind_closeradar_large_usen/1L.jpg?1213024402403 ~/Library/WeatherMaps/latest1.jpg;
curl -s http://image.weather.com/looper/archive/us_ind_closeradar_large_usen/2L.jpg?1213024402403 ~/Library/WeatherMaps/latest2.jpg;
curl -s http://image.weather.com/looper/archive/us_ind_closeradar_large_usen/3L.jpg?1213024402403 ~/Library/WeatherMaps/latest3.jpg;
curl -s http://image.weather.com/looper/archive/us_ind_closeradar_large_usen/4L.jpg?1213024402403 ~/Library/WeatherMaps/latest4.jpg;
curl -s http://image.weather.com/looper/archive/us_ind_closeradar_large_usen/5L.jpg?1213024402403 ~/Library/WeatherMaps/latest5.jpg;

defaults write com.apple.desktop ChangeTime 1;
killall Dock;

exit 0
Edit the script to suit your location by retrieving the image URLs from weather.com or somewhere else. I've added the commands to reset the refresh interval and restart the dock, because in my experience, this stops working after a couple hours without doing so. Drop the script in the /Library/Scripts folder. Also make sure to make it executable with this command: sudo chmod 750 /Library/Scripts/get_weather_radar.sh

Now, open System Preferences, go to Desktop & Screensaver, and specify ~/Library/WeatherMaps as the folder to load images from. Check the Change Picture option and don't bother setting the interval. The preference pane doesn't let you set it below five seconds (and for good reason, given the load this imposes on the CPU). Now, create a launchd agent to periodically run the retrieval script above. Save the file as GetWeather.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>GetWeather</string>
<key>ProgramArguments</key>
<array>
 <string>/Library/Scripts/get_weather_radar.sh</string>
</array>
<key>StartInterval</key>
<integer>600</integer>
</dict>
</plist>
Place the agent in your ~/Library/LaunchAgents folder and load it with this command:
launchctl load -w ~/Library/LaunchAgents/GetWeather.plist
If it loaded correctly, you should see a folder full of pictures named WeatherMaps in your ~/Library folder, the dock should have restarted, and your desktop should be showing you weather maps. The launchd agent will automatically retrieve the images every 10 minutes and restart the dock, and they will be displayed with about a one-to-two second delay, showing the radar "in motion."

Of course, you could just use one of the many weather map Dashboard widgets, but what fun would that be!?

Comments (6)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20080611114658430