user229564
user229564

Reputation:

Determining the Destination of a Message for Sandboxing in Cocoa

So I just added sandboxing to one of my products. It's totally functional except that the final step in the workflow is to set the desktop. It does this via NSWorkspace. When I call

[[NSWorkspace sharedWorkspace] setDesktopImageURL:[NSURL fileURLWithPath:imagePath]
                                        forScreen:screen
                                          options:nil
                                            error:&error];

I receive the following error:

*** attempt to post distributed notification 'com.apple.desktop' thwarted by sandboxing.

Right, so I need a temporary exception like so:

<key>com.apple.security.temporary-exception.apple-events</key>
<array>
    <string>XXXXX</string>
</array>

So ultimately I need to figure out what goes in the XXXXX, right? What handles desktop settings? And, more generically, is there a simple way to determine the target bundle of a message?

Upvotes: 1

Views: 631

Answers (2)

KRASH
KRASH

Reputation: 326

I experienced the same problem, but I found a different workaround. By enabling the "Allow Calendar Data Access" entitlement, setting a new wallpaper through NSWorkspace works.

I know this is a pretty strange workaround and I don't know if it is future-proof (Apple may block it in future versions). It works at the time of writing, and I thought it was worth sharing it with the next person having this problem.

Upvotes: 1

gcbrueckmann
gcbrueckmann

Reputation: 2453

AFAIK there isn’t any exception for setting the wallpaper. Also, sandboxing seems to kill off not the NSWorkspace method itself, but rather a distributed notification (that’s what the log says). So, if this NSWorkspace method is implemented using distributed notifications, it must use a payload (-[NSNotification userInfo]), but payloads aren’t allowed with sandboxing.

If you want to go the Apple Event route, you can always try changing the wallpaper using AppleScript (though that only allows you to change that of the main screen):

tell application "Finder" to set the desktop picture to the_image_file

(Where the_image_file is whatever image you want to set.)

Upvotes: 0

Related Questions