Skip to content

Instantly share code, notes, and snippets.

@colby
Created November 1, 2010 07:41
Show Gist options
  • Select an option

  • Save colby/657791 to your computer and use it in GitHub Desktop.

Select an option

Save colby/657791 to your computer and use it in GitHub Desktop.
Connects to simpledesktops.com and grabs a random image to assign as your profiles desktop image.
import random
import urllib
import urllib2
import tempfile
import subprocess
from appscript import app, mactypes
import lxml.html as lh
url = "http://simpledesktops.com/browse/"
random_page = str(random.randint(1,20))
random_image = str(random.randint(1,29))
website = urllib2.urlopen(url + random_page)
parse = lh.parse(website)
link = parse.xpath("//div[@class='desktop']/a")
grab_image = link[1].get('href')
set_desktop = tempfile.mkstemp()
urllib.urlretrieve(grab_image, set_desktop[1])
app('Finder').desktop_picture.set(mactypes.File(set_desktop[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment