#! /usr/bin/python

# usage: wallpaper /path/to/wallpaper/dir
#
# choses a random file from the specified directory (including subdirs) and
# makes it your Gnome wallpaper. GConf rocks!


wallpaper_path = "/desktop/gnome/background/picture_filename"

import os
import time
import random
import sys
import gconf

def getFiles(parent):
        files = []
        for filename in os.listdir(parent):
                filepath = "%s/%s" % (parent, filename)
                if os.path.isdir(filepath):
                        files = files + getFiles(filepath)
                else:
                        files.append(filepath)
        return files

random.seed(int(time.time()))
client = gconf.client_get_default()
files = getFiles(sys.argv[1])

try:
        files.remove(client.get_string(wallpaper_path))
except ValueError:
        pass

client.set_string(wallpaper_path, random.choice(files))
