开发者

Changing the desktop image in 10.6.x

开发者 https://www.devze.com 2022-12-08 07:49 出处:网络
I have an application that changes the desktop background for users based on files they specify. It worked quite well in 10.4 and 10.5, but Apple seems to have changed some system notifications which

I have an application that changes the desktop background for users based on files they specify.

It worked quite well in 10.4 and 10.5, but Apple seems to have changed some system notifications which means the code I had written no longer works.

I was wondering if anyone has seen any examples, or have worked out how to change the image? It seems they still use the com.apple.desktop property list, but the notification of the file change doesn't seem to work anymore.

I used to notify the OS of the new background using this command:

开发者_高级运维
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"com.apple.desktop" object:@"BackgroundChanged"];

Any ideas?


Well you were using undocumented API. Not surprising it stopped working…

10.6 has new public API on NSWorkspace. In particular the -setDesktopImageURL:forScreen:options:error: method.


You can also call an Applescript to change the wallpaper image.

tell application "Finder"
    set image_file to POSIX file "/Users/user/Pictures/wall.jpg"
    set desktop picture to image_file
end tell

And you can use an NSAppleScript object to call Applescript with your Cocoa application.

0

精彩评论

暂无评论...
验证码 换一张
取 消