开发者

Determining the Destination of a Message for Sandboxing in Cocoa

开发者 https://www.devze.com 2023-03-26 16:10 出处:网络
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

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, m开发者_开发问答ore generically, is there a simple way to determine the target bundle of a message?


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.


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.)

0

精彩评论

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

关注公众号