Random images from xkcd as wallpaper

After howto use real-time earth wallpaper i tired to make some random xkcd images as my wallpaper.
The below is a simple script which one can use to get random images from xkcd as desktop wallpapers at a time interval of 3600 seconds

Steps:
1. mkdir -p ~/.xkcd 
2. Place the code in this dir, call it xkcds.bash.
3. Setup a cron job or put the code in rc, as :
0 * * * *  ~/.xkcd/xkcds.bash
[or]
cp ~/xkcd/xkcds.bash /etc/init.d/ && update-rc.d xkcds.bash defaults

#!/bin/bash

while [ 1 ]; do

# Remove old images if any!
rm -rf *.png

#Get the random image
wget $(curl -sL "http://dynamic.xkcd.com/random/comic/" \
    | grep "http://imgs.xkcd.com/comics/"\
    | awk -Fsrc=\" '{print $2}'\
    |awk -F\" '{print $1}') -O xkcd-$(date +'%S').png

#Set the image based on the desktop session

[[ $DESKTOP_SESSION == "gnome"]] && gconftool-2 --type string --set \
/desktop/gnome/background/picture_filename ~/.xkcd/xkcd*.png

[[ $DESKTOP_SESSION == "kde" ]] &&  dcop kdesktop KBackgroundIface \
setWallpaper xkcd*.png 1

#Have a nap
sleep 3600

done
Share this