Created
January 8, 2013 15:26
-
-
Save grahamc/4484630 to your computer and use it in GitHub Desktop.
Set your background photo from @apod on Twitter. Requires: - mechanize - appscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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