Bing picture of the day on your desktop.

Jan 31, '12 07:30:00AM

Contributed by: Anonymous

Bing has those nice images on www.bing.com and every day they have a new one. I have put together a small python script which fetches today's image and displays it on the desktop.

Note: you will need to manually create the DeskFeed folder inside your Pictures folder.

Here's the script:

#!/usr/bin/env python
import os
import md5
import pprint
import sys
import subprocess
from time import strftime
from urllib import URLopener
from urllib2 import urlopen
from xml.dom.minidom import parseString

# Defines source and destination of image
rss_feed = 'http://feeds.feedburner.com/bingimages';
dst_dir = os.path.expanduser('~/Pictures/DeskFeed/')

SCRIPT = """/usr/bin/osascript<<END
tell application "Finder"
set desktop picture to POSIX file "%s"
end tell
END"""


def set_desktop_background(destination):
  subprocess.Popen(SCRIPT%destination, shell=True)

def parseFeed(rss):
  destination = "%s%s.jpg" % (dst_dir, strftime( "%y-%m-%d"))
  if os.path.exists(destination):
    sys.exit(0)



  try:
    rss_contents = urlopen( rss )
  except:
    print "Failed to read rss feed %s" % rss
    return
  rss_src = rss_contents.read()
  rss_contents.close()
  dom = parseString( rss_src )
  firstitem = dom.getElementsByTagName('item')[0]
  link = firstitem.getElementsByTagName( 'enclosure' )[0].getAttribute('url')
  URLopener().retrieve(link, destination)
  set_desktop_background(destination)


def main():
  parseFeed(rss_feed)

if __name__ == "__main__":
  main()
This, and other useful scripts, are available here.

[crarko adds: I tested this, and it works as described. To actually run the Python script I recommend studying the brief tutorial here. I used the Python Launcher utility from MacPorts to manage the script.]

Comments (7)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20110721062846337