OK. Looking at that, here we go.
#1, it's sandboxed. Why we need to sandbox changing the desktop picture is beyond me, but it is.
#2. It works in 10.6.8
#3. It uses what is called NSDesktopImages.
Then the magic happens here:
NSURL *imageURL = [[NSWorkspace sharedWorkspace] desktopImageURLForScreen:curScreen];
setDesktopImageURL:imageURL
forScreen:curScreen
options:screenOptions
error:&error])
The class used is called NSWorkspace and the method used to set the desktop image is desktopImageURLForScreen.
In Objective-C's Cocoa, set accessors are created for property variables by capitalizing their first letter and prepending "set" onto it.
So, one might see setDesktopImageURL and expect that there would be a public property they could set called desktopImageURL.
But this is a method with multiple method names, which is standard in Objective-C.
The method inside of NSWorkspace really is setDesktopImageURL: forScreen: options: error:
Here is the section of the header file for NSWorkspace (NSWorkspace.h) that deals with this part of desktop image management.
There are a few more bits after this, but these are the three methods that exist for handling desktop images within NSWorkspace. Method names in bold. Code follows.
/* Desktop images */
@interface NSWorkspace (NSDesktopImages)
/* Sets the desktop image for the given screen to the image at the given URL. The URL must be a file URL and may not be nil. The options dictionary may contain any of the NSWorkspaceDesktopImage keys, which control how the image is scaled on the screen. This returns YES if the image was successfully set; otherwise, NO is returned and an error is returned by reference.
You should normally NOT present a user interface for picking the options. Instead, just choose appropriate defaults and allow the user to adjust them in the System Preference Pane.
*/
- (BOOL)setDesktopImageURL:(NSURL *)url forScreen:(NSScreen *)screen options:(NSDictionary *)options error:(NSError **)error AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
/* Returns the URL for the desktop image for the given screen.
*/
- (NSURL *)desktopImageURLForScreen:(NSScreen *)screen AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
/* Returns the options dictionary for the desktop image for the given screen.
*/
- (NSDictionary *)desktopImageOptionsForScreen:(NSScreen *)screen AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
@end
Cheers,
- Alex
On May 12, 2014, at 1:17 PM, 2551 wrote:
I wrote a simple bash script that would swap out desktop images that worked up unitl Mavericks broke it. I did mess around trying to figure out what they'd changed but eventually got frustrated and lost interest.
There is a Cocoa Sample project on Apple's developer site that works for Mavericks. Reading through the code (for those who speak Cocoa) might offer some clues about what you need to do in AppleScript. At the very least it might be possible to translate the relevant parts into an ASObjC library or some such. The project's called 'DesktopImage' and can be found here:
Best
P