# bom_radar_desktop
#
# A bash script to display the latest weather radar image from the
# Australian Bureau of Meteorology as your GNOME desktop background.
#
# Version 1.0.0  28th February 2007
#
# Copyright (C) 2007  John Dalton <john.dalton@daltons.info>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


# Running this script from the command line will set your desktop
# to the current radar image.
# You can use cron to run this file every 10 minutes, so keeping
# the latest radar image displayed as your desktop background.
# Note that the image is updated on the BOM's website approximately
# 3:46 after it is acquired, so for minimum latency the image should
# be downloaded at 4, 14, 24, 34, 44 and 54 minutes past the hour.
# If you have saved this script in the file /usr/local/bin/,
# the crontab line to do this is:
# 4-59/10 *  * * *   /usr/local/bin/bom_radar_desktop

# The URL from which the weather map will be downloaded.
# In the case of the Sydney radar the map appears on the
# web site 3 minutes 46 seconds after it is acquired.
# The URLs for radars other than Syndey can be gleaned
# from the page: http://mirror.bom.gov.au/weather/radar/index.shtml

MAP_URL=http://mirror.bom.gov.au/radar/IDR033.gif

# Create a unique temporary file in the /tmp directory
# in which to store the map.  The name of the
# temporary file will start with "weather_map".
# Note that we cannot just store each successive map
# with the same filename as GNOME caches the desktop image
# and will not read the new image unless it has a different
# filename.

TMPFILE=`mktemp -t weather_map.XXXXXXXXXX` || exit 1

# Download the latest weather map to the temporary file

wget http://mirror.bom.gov.au/radar/IDR033.gif -q -O $TMPFILE

# Set the GNOME desktop picture to the file just downloaded.

gconftool-2 -t str --set /desktop/gnome/background/picture_filename $TMPFILE

# Centre the picture on the desktop.  You can also do things like fit the
# map to the desktop by changing the value set here.

gconftool-2 -t str --set /desktop/gnome/background/picture_options "centered"

# Give GNOME time to cache the image then keep the /tmp directory
# neat by deleting the file.  It seems to be safe to delete the file
# once GNOME has cached it.

sleep 10
rm $TMPFILE

