Setting background image of individual desktops in OSX Lion
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 ea开发者_如何转开发ch? Many thanks!
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.
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
精彩评论