Rotating Wallpaper in Gnome 3 With Python

And now for one of those things that will interest only me - a little python script to rotate wallpaper images from a directory in Gnome 3 (for Gnome Shell or Unity in Ubuntu 11.10).

Note: Updated with suggestion from Paul in the comments.
Note: Another update from Tyler. Geeze I wish I was smarter :).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/python

import os
import random
import mimetypes

backgrounds = os.environ['HOME'] + "/Pictures/wallpapers/"
items = []

for item in os.listdir(backgrounds):
if "image" in mimetypes.guess_type(item)[0]:
items.append (item)


item = random.randrange (0, len (items))
os.system('gsettings set org.gnome.desktop.background picture-uri "file:///' + backgrounds + items[item] + '"' )