Weather Radar Desktop Background
Sample image from NOAA radar weather image
The United States National Oceanic and Atmospheric Administration (NOAA) provides high quality weather forecasts and current weather condition information online. One of their features is a complete ground-based radar map of the entire lower 48 states, in a single, very large image file. I decided that it would be useful and pretty cool to have this large radar weather map as my dual-monitor desktop background. It would only be useful and cool if it updated itself automatically every few minutes, so I could quickly see what the weather was going to be.
To do this, I first needed to find a way to change the desktop background in Gnome using command-line tools. After a bit of searching, I found that the gconftool-2 utility can edit configuration settings in the gconf world. This is similar to the Windows registry, but for the Gnome desktop. The key /desktop/gnome/background/picture_filename can be used to set the picture filename, and the key /desktop/gnome/background/picture_options can be used to set the display mode of the picture. For this image, I decided that “stretched” was the best option.
We also need to be able to fetch the current radar image from the NOAA website, and to do that we can use the wget utility. We use the -O option to ensure that the image is always saved with the same filename.
I wrote the following short script, and put an entry into my crontab to run this script every 10 minutes.
#!/bin/bash
cd /home/matthew/
wget http://radar.weather.gov/Conus/RadarImg/latest.gif -O latest.gif &> /dev/null
gconftool-2 -t str --set /desktop/gnome/background/picture_filename /home/matthew/latest.gif
gconftool-2 -t str --set /desktop/gnome/background/picture_options "stretched"
Crontab entry:
*/10 * * * * matthew /home/matthew/get_radar_map.sh
OSX Update:
To get this working on OSX, where we can’t use the Gnome tools to update the desktop, first create a little applescript, similar to this one. Desktop 2 refers to my external monitor, change it to “default desktop” if you want the main screen to update. If we simply said to display “latest.gif”, it wouldn’t update the image, so we have to tell it to display the old image, then display the latest image.
tell application "System Events"
tell desktop 2
set picture rotation to 0
set picture to POSIX file "/Users/matthew/weather/older.gif"
set picture to POSIX file "/Users/matthew/weather/latest.gif"
end tell
end tell
Then, edit the main shell script called from Cron to call the applescript. We also need to specify the full path to wget, since the PATH can’t be relied upon.
#!/bin/bash
cd /Users/matthew/weather/
mv latest.gif older.gif
/opt/local/bin/wget http://radar.weather.gov/Conus/RadarImg/latest.gif -O latest.gif &> /dev/null
osascript update_background.as
Great article
.Keep on the good work!