Reputation: 14917
I have a little PyObjC script to change desktop images to a particular file (which is fetched from flickr). It sets a different image for each screen, should you have multiple. This worked fine in Snow Leopard, but in Lion you can set background images for individual desktops (formally Spaces), whereas in Snow Leopard all Spaces shared the same background.
I'm currently using setDesktopImageURL:forScreen:options:error:
on [NSWorkspace sharedWorkspace]
, but that only sets the image on the current space/desktop.
Any ideas how I might iterate over the desktops and set images on each? Many thanks!
Upvotes: 4
Views: 1951
Reputation: 116
Although I don't think there's a supported API for this, you should be able to do it using the defaults
command line utility. The desktop images are stored on a per-space basis in ~/Library/Preferences/com.apple.desktop.plist, and can be read and written as described in Clinton Blackmore's answer here: How can I programmatically change the background in Mac OS X?. You'll obviously have to change the command a bit to modify the spaces dictionary instead of default, but it should otherwise work the same.
Upvotes: 2
Reputation: 35081
You can get all the screens as an NSArray using [NSScreen screens]
and then iterate over that array setting the desktop image for each screen. Apple have some sample code: http://developer.apple.com/library/mac/#samplecode/DesktopImage/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008860
Upvotes: 2