Change background wallpaper randomly on Ubuntu 8.10 (Intrepid Ibex)

Get bored with the default wallpaper? If yes, let's have some fun!

  1. download suitable wallpapers from art.gnome.org using ftp. Assume your screen resolution is 1280x1024, so we can download all the wallpapers from art.gnome.org into $HOME/Pictures/Wallpapers/art.gnome.org. Please create the directory yourself :-)
    ftp ftp.gnome.org 
    Connected to ftp.acc.umu.se. 220 (vsFTPd 2.0.6) 
    Name (ftp.gnome.org:root): anonymous 
    331 Please specify the password. 
    Password: 
    230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. 
    ftp> cd /pub/GNOME/teams/art.gnome.org 
    250 Directory successfully changed. 
    ftp> bin 
    200 Switching to Binary mode. 
    ftp> prompt off 
    Interactive mode off. 
    ftp> mget *1280x1024.jpg 
    Ok, now you should have lots of wallpapers ready to load.
  2.  Change to a random wallpaper from command line
    export WALLPAPER_DIR=$HOME/Pictures/Wallpapers
    /usr/bin/gconftool-2 -t str -s /desktop/gnome/background/picture_filename "`find $WALLPAPER_DIR -name \*.jpg | sort -R | tail -n 1`"
  3. Pretty cool right? Now let’s create a shell so you don’t need to remember it each time. Save it as $HOME/bin/random_wallpaper
    #!/bin/sh
    echo "Changing to a random wallpaper"
    WALLPAPER_DIR=$HOME/Pictures/Wallpapers
    /usr/bin/gconftool-2 -t str -s /desktop/gnome/background/picture_filename "`find $WALLPAPER_DIR -name \*.jpg | sort -R | tail -n 1`"
     
  4. Setup a cronjob to run the script every minute! no, every 10 minutes maybe better. Make sure your user account in /etc/cron.allow otherwise it won’t run your script!

    chmod a+x $HOME/bin/random_wallpaper
    crontab -e
    */10 * * * * /home/hkai/bin/random_wallpaper
     
  5. Its running but the wallpaper is not changing! Why, I’m not sure, should be some environment parameters related to Dbus or Xauthority. So we need to put the environment into the script each time we login since it’s changing each time you login to gnome.
    DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-wqQ5W7fMS4,guid=6b489fd5651208f06087bb45492cb471
    XAUTHORITY=/tmp/.gdmN7XVKU

    So we need another script which generate the random_wallpaper each time after we login. Save it as $HOME/bin/generate_wallpaper_script
    #!/bin/sh

    SCRIPT_FILE=$HOME/bin/random_wallpaper
    WALLPAPER_DIR=$HOME/Pictures/Wallpapers

    # Export the dbus session address on startup so it can be used by cron
    echo ‘#!/bin/sh\n\n’ > $SCRIPT_FILE

    echo ‘echo “Changing to a random wallpaper”\n’ >>$SCRIPT_FILE
    echo ‘WALLPAPER_DIR=’$WALLPAPER_DIR >>$SCRIPT_FILE
    echo ‘export WALLPAPER_DIR’ >>$SCRIPT_FILE

    env | grep DBUS_SESSION_BUS_ADDRESS >> $SCRIPT_FILE
    echo ‘export DBUS_SESSION_BUS_ADDRESS’ >> $SCRIPT_FILE
    env | grep XAUTHORITY >> $SCRIPT_FILE
    echo ‘export XAUTHORITY’ >> $SCRIPT_FILE

    echo ‘echo “Old wallpaper:” `/usr/bin/gconftool-2 -g /desktop/gnome/background/picture_filename`’ >> $SCRIPT_FILE

    echo ‘/usr/bin/gconftool-2 -t str -s /desktop/gnome/background/picture_filename “`find $WALLPAPER_DIR -name \*.jpg | sort -R | tail -n 1`”‘ >> $SCRIPT_FILE

    echo ‘echo “New wallpaper:” `/usr/bin/gconftool-2 -g /desktop/gnome/background/picture_filename`’ >> $SCRIPT_FILE
     
  6. Now add the script into gnome session so it will run each time after you login.
    Wait 10 minutes see if the wallpaper is changing and relax.
  7. I'd uploaded the script here. generate_wallpaper_script

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer