Using a random, rotating Gnome wallpaper

To change the wallpaper randomly, there are a few things on the to-do list:

Finding a random wallpaper and applying it

First of all, we need to select a random wallpaper from a directory. The following command should do that, using the /opt/wallpapers directory:

    for f in /opt/wallpapers/*; do echo $RANDOM:$f; done |
    sort -n | head -n 1 | cut -d: -f2-

Now, to let Gnome know about the new wallpaper:

gconftool-2 -s /desktop/gnome/background/picture_filename -t string "$wallpaper"

Changing the wallpaper every hour

Wrap the two commands in a script and place the script in $HOME/


gconftool-2 -s /desktop/gnome/background/picture_filename -t string "`
    for f in $dir/*; do echo $RANDOM:$f; done |
    sort -n | head -n 1 | cut -d: -f2-

Make the script executable:

chmod +x $HOME/

Finally, add the following line to /etc/crontab, replacing both username instances with your actual username:

7 * * * * username env `dbus-launch` sh -c 'trap "kill $DBUS_SESSION_BUS_PID" EXIT; /home/username/'

This will run the wallpaper changing script every hour at the 7th minute.