I am trying to read a file in sandbox mode outside application sandbox. I went through this objColumnist post, and definitely Apple's App Sandbox Design Guide
documentation.
Documentation clearly states that you need a NSOpenPanel
or NSSavePanel
to read/write files in Security-Scoped Bookmarks
.
If your app employs a download or processing folder that is outside of the app container, obtain initial access by presenting an NSOpenPanel dialog to obtain the user’s intent to use a specific folder
My use case is a bit different, I want to read a file from finder. Like when user triggers some hotkey from finder, i will get the selection from finder (using scripting bridge to get file selection) and then read that file. Hence i can not create a Security-Scoped Bookmarks
.
So is there an alternative way to read a bookmark file. Or is there other way other than scripting bridge to get finder selection that fits in with app sandbox as well.
There is a way to get this done: Use NSService to publish a File-Service in the Finder > Services Menu https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/SysServices/Articles/overview.html#//apple_ref/doc/uid/20000850-BCIDHJJA
The user selects a file in the Finder, calls the service thru either the context menu, a shortcut/hotkey or the Finder menu. You'll receive a security scoped bookmark on which you then can access the file.
The way with AppleScript will not be allowed in the Mac App Store as you cannot get an entitlement to script Finder.