Skip to content

Instantly share code, notes, and snippets.

@grahamc
Created January 8, 2013 15:26
Show Gist options
  • Save grahamc/4484630 to your computer and use it in GitHub Desktop.
Save grahamc/4484630 to your computer and use it in GitHub Desktop.
Set your background photo from @apod on Twitter. Requires: - mechanize - appscript
#!/usr/bin/env python
import mechanize
from appscript import app, mactypes, its
from datetime import date
d = date.today()
br = mechanize.Browser()
url = 'http://apod.nasa.gov/apod/ap%s.html' % d.strftime("%y%m%d")
br.open(url)
for link in br.links():
if link.url.startswith('image/'):
resp = br.follow_link(link)
with open('todays-photo', 'w') as fo:
fo.write(resp.read())
break
se = app('System Events')
desktops = se.desktops.display_name.get()
for d in desktops:
desk = se.desktops[its.display_name == d]
desk.picture.set(mactypes.File('todays-photo'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment