• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: name of the current desktop picture
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: name of the current desktop picture


  • Subject: Re: name of the current desktop picture
  • From: Alex Zavatone <email@hidden>
  • Date: Mon, 12 May 2014 13:48:32 -0400

FYI, the code for this in 10.9 seems to be identical within NSWorkspace, and should work for 10.8 and 10.9.

I don't have 10.9 running at the moment, so I can't test it.  

Anyone with a developer license or working version of Xcode 4.2 - 5.1.1 should be able to download, build and run and test the DesktopImage project without a problem.

If you've got any of the above version of Xcode, this project is already on your hard drive within the help.

Is any of this exposed to AppleScript?  I have no idea.

Good luck.
- Alex


On May 12, 2014, at 1:40 PM, Alex Zavatone wrote:

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:

https://developer.apple.com/library/mac/samplecode/DesktopImage/Introduction/Intro.html

Best


P

Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/archives/applescript-users This email sent to email@hidden
References: 
 >Re: name of the current desktop picture (From: John Baltutis <email@hidden>)
 >Re: name of the current desktop picture (From: Robert Poland <email@hidden>)
 >Re: name of the current desktop picture (From: Luther Fuller <email@hidden>)
 >Re: name of the current desktop picture (From: Alex Zavatone <email@hidden>)
 >Re: name of the current desktop picture (From: Alex Zavatone <email@hidden>)

  • Prev by Date: Re: name of the current desktop picture
  • Next by Date: Re: name of the current desktop picture
  • Previous by thread: Re: name of the current desktop picture
  • Next by thread: Re: name of the current desktop picture
  • Index(es):
    • Date
    • Thread