更改 OS X 10.7 Lion 中所有桌面上的壁纸?
我想更改屏幕上所有桌面(以前的“空间”)的壁纸。从 OS X 10.6 开始,NSWorkspace 有一个类别允许设置壁纸,但是,当我使用此功能时,只有当前桌面的壁纸会更改,所有其他桌面保持不变。
然后我查看了桌面首选项 plist 并编写了一个类来修改它以反映我想要的更改(基本上设置一个新的图像文件路径)。保存新文件后,我发送了 com.apple.desktop“BackgroundChanged”通知 - Google 如果您不知道我在说什么,这就是人们在 10.6 之前更改壁纸的方式。起初这并没有产生任何结果,所以我没有发送“nil”作为 userInfo 字典,而是发送了与 Apple 在设置中更改壁纸时完全相同的 userInfo 字典(订阅应用程序中的通知并更改壁纸)在设置应用程序中,您将看到它的样子)。幸运的是,当我以这种方式发送通知时,由于某种原因,Dock 崩溃了,当它重新加载时,它从首选项文件中加载了设置,从而显示了我的更改。
这适用于 10.7.1,但是,我希望 a) 不想让扩展坞崩溃和重新加载带来糟糕的用户体验,b) 使用或多或少保证在未来版本中也能工作的路径。利用错误似乎并不是一条稳定的道路。
关于如何更改所有桌面的壁纸还有其他想法吗?我也不确定 NSWorkspace 壁纸类别的当前行为是有意为之还是错误,但是,从壁纸首选项窗格的行为来看,似乎是前者。
I would like to change the wallpaper of all desktops (formerly "spaces") on a screen. As of OS X 10.6 there is a category to NSWorkspace which allows the setting of the wallpaper, however, when I use this function only the wallpaper of the current desktop gets changed and all the other desktops remain unchanged.
I then looked at the desktop preferences plist and wrote a class that modifies it to reflect the changes I want (basically set a new image file path). After the new file was saved I sent the com.apple.desktop "BackgroundChanged" notification - Google if you don't know what I am talking about, this was how people changed wallpapers in pre 10.6 days. At first this didn't produce any result, so instead of "nil" as userInfo dictionary I sent the exact same userInfo dictionary along as Apple does when you change the wallpaper in your settings (subscribe to the notification in an app and change the wallpaper in the settings app and you will see what it looks like). Luck helped me here, when I sent the notification this way for some reason the Dock crashed and when it reloaded, it loaded the settings from the preferences file thus displaying my changes.
This works on 10.7.1, however, I would a) rather not have the bad user experience of the dock crashing and reloading, and b) use a path that is more or less guaranteed to work in future releases as well. Exploiting a bug doesn't seem like a stable path.
Any other ideas on how to change the wallpaper of all desktops? I am also unsure whether the current behaviour of the NSWorkspace wallpaper category is intended or a bug, however, judging from the behaviour of the wallpaper preferences pane it seems that the former is the case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有用于为所有屏幕或所有空间设置相同壁纸的 api, NSWorkspace setDesktopImageURL 的实现方式是仅为当前屏幕上的当前空间设置壁纸,系统偏好设置也是如此。
除了手动修改〜/ Library / Preferences / com.apple.desktop.plist(格式可能会改变)并使用通知重新加载它(您经历过的崩溃)的易失性方法之外,您可以做的是将壁纸设置为用户的空格切换到它,例如寻找 NSWorkspaceActiveSpaceDidChangeNotification (如果您的应用程序并不总是运行,您可以告诉用户切换到他想要应用壁纸的所有空间),可以说这些方法并不理想,但至少它们不是不稳定的。
There is no api for setting the same wallpaper to all screens or all spaces, NSWorkspace setDesktopImageURL it is implemented as such that it only sets the wallpaper for the current space on the current screen, this is how System Preferences does it too.
Besides the volatile method of manually modifying the ~/Library/Preferences/com.apple.desktop.plist (format could change) and using notifications to reload it (crashes you experienced) what you can do is set the wallpaper to spaces as the user switches to it , e.g. look for NSWorkspaceActiveSpaceDidChangeNotification (if your application is not always running you could tell the user to switch to all spaces he wants the wallpaper to apply to) , arguably these methods are not ideal but at least they are not volatile.