Python script to change OS X wallpaper independently on all connected monitors based on a supplied "theme" keyword.
I usually work with two (external) monitors at home, and three (laptop + 2 external) at work, generally with 4 virtual desktops ("Spaces" in OS X), and I wanted a way to change the backgrounds for all the monitors in a particular space based on a theme of my choosing. My solution? Create a "wallpapers" folder (I sync mine via Dropbox, but that's another story, and not necessary for this script to work), set a WALLPAPER environment variable that points to that folder (I do this in my .bash_profile), and then tag the images in that folder with one or more "theme" descriptors, each of which is prefixed with "wp_",e.g., wp_dragonfly, wp_solarsystem, wp_titan (the moon of Saturn), etc. When I want to update the theme on a particular desktop I just type "chgwp dragonfly" in Terminal.app (or the terminal of your choice) on that particular desktop, and each of the displays is updated to a unique image bearing that tag from my wallpapers folder. If I just type "chgwp" without a theme, something gets chosen randomly from that folder.
NOTE: This script relies on the availablility of the following modules that come with the "stock" OS X Python:
from AppKit import NSWorkspace, NSScreen
from Foundation import NSURL
Now *my* default version of Python is *not* the standard OS version, but you can specify which version of Python is called in various ways. To use this script I simply make it executable and include the following as the first line:
#!/usr/bin/python
You can point to a different version of Python, say that installed using Homebrew, by changing that first line to the following, e.g., if you've installed a particular package using brew and don't want to use the standard OS version of Python.
#!/usr/local/bin/python