Script to download and set a random wallpaper in Nautilus

28
Dec
2009

This snippet downloads a random image from the wonderful InterfaceLIFT; it should work when called from cron. From command line works reliably. Note that the 'wget' command is all one line.

#!/bin/bash

# Change this line to match your location:
location='/complete/path/to/local/wallpapers/dir'

# Change this to your resolution (use fullscreen for 4:3 sizes):
# resolution='fullscreen/1280x1024/'
resolution='widescreen/1920x1200/'
templog=$(tempfile) || exit

wget --quiet --user-agent "Mozilla" --output-document - "http://interfacelift.com/wallpaper_beta/downloads/random/$resolution" | grep --max-count 1 --only-matching '.wallpaper_beta.load.[0-9].*jpg' | wget --no-verbose --user-agent "Mozilla" --timestamping --input-file - --output-file $templog --base 'http://interfacelift.com/' --directory-prefix $location

wpfile=$(awk 'NR==1 { print $6 | "sed s/\\\"//g" }' $templog)

if [ -f "$wpfile" ]; then
    echo "New wallpaper: $wpfile"
    touch "$wpfile"

    # command="/usr/bin/dbus-launch /usr/bin/gconftool"
    command="/usr/bin/gconftool"

    ${command} --type string --set /desktop/gnome/background/picture_filename $wpfile
    ${command} --type string --set /desktop/gnome/background/picture_options centered
    ${command} --type string --set /desktop/gnome/background/primary_color black
fi

rm -f $templog