Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
set/get wallpaper from on mac OS
#!/usr/bin/env python
# vim: set et sw=4 ts=4 sts=4 fdm=syntax ff=unix fenc=utf8:
set/get wallpaper from on mac OS
require appscript module, sudo easy_install appscript
import urllib2, re, os
from appscript import *
path = './wallpaper/'
display_name = 'DELL E2311H' # my second display, the default display_name is 'Color LCD'
def getWallPaper():
url = ''
req = urllib2.urlopen(url).read()
p = re.compile(r'<img src="http.*\.png')
return p.findall(req)
def setWallPaper(wallpaper):
se = app('System Events')
desktops = se.desktops.display_name.get()
desk = se.desktops[its.display_name == display_name]
if __name__ == "__main__":
imgs = getWallPaper()
for (idx, img) in enumerate(imgs):
img = re.sub('\.([0-9]+)x([0-9]+)_q100\.png', '', img[10:])
filename = re.sub('^.*/','',img)
os.system('wget -c '+img+' -P ./wallpaper >/dev/null 2>&1 &')
if idx is 0:
wallpaper = path+filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment