views:

135

answers:

2

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?

+6  A: 

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.

Mike Abdullah
I'm not surprised it stopped working, just wondering how to fix it :DThanks for the post, i'll try it and see how I go.
d2kagw
+1  A: 

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.

zonble