Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OS X: Open file in finder + App Sandbox

I try to open a finder window which works fine but every time I do this there is 1 second delay and an error logged.

[[NSWorkspace sharedWorkspace] selectFile:@"Users/[TheUser]/Downloads" inFileViewerRootedAtPath:pathStr];

The log displays:

__CFPasteboardIssueSandboxExtensionForPath: error for [/Users/TheUser/Downloads/]

Is this normal? I have enabled entitlements and allowed Downloads folder access.

like image 714
user610246 Avatar asked Aug 03 '11 14:08

user610246


1 Answers

A bit late, but I just stumbled over this as well and found an answer for this. For this warning/error/whatever it is to disappear, you need to have a security scoped URL to the path (and thats the point where it might be tricky for you, because to obtain such an URL, you must use an NSOpenPanel and annoy the use, even though you have the right entitlement for the folder!).

Once you have that security scoped URL, you have to call the startAccessingSecurityScopedResource method and afterwards make your call to NSWorkSpace. Don't forget to call stopAccessingSecurityScopedResource afterwards (you can do it immediately after the selectFile:inFileViewerRootedAtPath: returned) to free up kernel resources and avoid being unable to make more calls to startAccessingSecurityScopedResource.

like image 186
JustSid Avatar answered Oct 05 '22 21:10

JustSid