在 OSX Lion 中设置各个桌面的背景图像
我有一个 PyObjC 脚本,用于将桌面图像更改为特定文件(从 flickr 获取)。如果您有多个屏幕,它会为每个屏幕设置不同的图像。这在 Snow Leopard 中效果很好,但在 Lion 中,您可以为单个桌面(正式的空间)设置背景图像,而在 Snow Leopard 中,所有空间共享相同的背景。
我目前正在 [NSWorkspace sharedWorkspace]
上使用 setDesktopImageURL:forScreen:options:error:
,但这仅在当前空间/桌面上设置图像。
有什么想法可以迭代桌面并在每个桌面上设置图像吗?非常感谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尽管我认为没有支持此操作的 API,但您应该能够使用
defaults
命令行实用程序来完成此操作。桌面图像按空间存储在 ~/Library/Preferences/com.apple.desktop.plist 中,并且可以按照 Clinton Blackmore 的回答中所述进行读取和写入:我怎样才能以编程方式更改 Mac OS X 中的背景?。显然,您必须稍微更改命令来修改空格字典而不是默认值,但它应该以其他方式工作。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.您可以使用
[NSScreen Screens]
将所有屏幕作为 NSArray 获取,然后迭代该数组,为每个屏幕设置桌面图像。苹果有一些示例代码: http://developer.apple.com/library/mac/#samplecode/DesktopImage/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008860You 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