Free DNS provides easy shared DNS hosting & URL forwarding

Monday, December 7, 2009

National Geographic Wallpapers

National Geographic is offering wallpaper-sized variants of many of their beautiful photo collections. One of the collections that I follow in iGoogle is the Photo of the day. I like it mostly because it doesn't have a particular theme and includes photos from many places around the world.
From time to time, I like some picture so much that I "go through all the trouble" (a 5-clicks process) and save it as my wallpaper.
I wanted something automated to do this (i.e. save the POD as my wallpaper). I know there is Opal (both for Windows & Linux), but I don't want to use it for two reasons:
  1. when I last tested it, it failed to work (i.e. it did not set any wallpaper)
  2. I fail to see the purpose of running a program full time (even if it's using almost none CPU & memory) just to update a file one time a day
Thus, I decided to practice my bash scripting & linux command skills to write a script that will save the National Geographic POG and set it as wallpaper in Gnome. This is what I came up with (it is not and will not be optimized nor use error control):
#!/bin/bash

# the URL of the photo feed
RSS_FEED=http://www.nationalgeographic.com/rss/photography/photo-of-the-day

# the prefix of the photos URL (used to find the newest photo)
IMAGE_URL_PREFIX=http://photography.nationalgeographic.com/staticfiles/

# format of the photo
# in = 270x179, sw = 800x600, lw = 1024x768, xl=1280x1024
IMAGE_FORMAT=sw

# directory where to save the images
IMAGE_DIRECTORY=~/Pictures

# retrieve the RSS feed, grep for the latest image and
# replace it's name to match the required format
IMAGE_URL=`wget -qO /dev/stdout $RSS_FEED | egrep -m 1 -o "$IMAGE_URL_PREFIX[^\"]*" | sed -e s/-in\.jpg\$/-$IMAGE_FORMAT\.jpg/`

# retrive the image
wget -q -nc -P $IMAGE_DIRECTORY $IMAGE_URL

# get the image file name
IMAGE_FILE=`basename $IMAGE_URL`

# set the image as background
gconftool -s -t string /desktop/gnome/background/picture_filename $IMAGE_DIRECTORY/$IMAGE_FILE
gconftool -s -t string /desktop/gnome/background/picture_options scaled

2 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. jackgessner is a spammer (posting links to adult websites).

    ReplyDelete