After seeing a friend's mac doing random Desktop background images I was suprised to find that Gnome Desktop currently doesn’t ship with an option to do the same; so I wrote my own. It’s a short shell (bash) script which you configure with the name of a directory to pick a random image from, and the name of a file which you’ll tell Gnome Desktop is your background. The script then picks a random image from the directory and creates a symbolic link with the name you specified.
If you call the script from a your ~/.bash_profile it’ll pick a new desktop image every time you log on.
If you call the script from a cronjob it’ll change the image after the time period you specify, and will flip to the new image right away.
You don’t have to use the script for changing background images, you can use it any time you need a random file from a directory.
#!/bin/bash
# This script picks a random file from a directory you specify, and creates a symlink to it.
# Uses include random desktop image
#edit the next 2 lines to suit your setup
symlink="/home//Pictures/backgrounds/random.jpg"
sourcedir="/home//Pictures/backgrounds/random"
tmpfile="/tmp/randomimage.txt"
#get list of images
find $sourcedir -type f > $tmpfile
#pick a random one
imagecount=`wc -l $tmpfile | awk '{print $1}'`
chosennum=`expr \( $RANDOM \% $imagecount \) + 1`
chosenimg=`head -n $chosennum $tmpfile | tail -n 1`
rm $symlink
ln -s "$chosenimg" "$symlink"
rm $tmpfile