I am trying to develop an application that also contains an extension for the Finder.
The extension can be used to create a new text file at the current Finder location. I have only added the following permissions to the entitlements file for both the main app and the extension:
com.apple.security.files.user-selected.read-only
I have implemented the FIFinderSync
protocol in my extension.
I added a menu item to create a new text file. Whenever I execute this method, the following error is shown in the Console:
Sandbox: Extension(4032) deny(1) file-write-create /Users/username/Documents/New Text.txt
The simplest way to get around this error is to add the following key:
com.apple.security.temporary-exception.files.home-relative-path.read-write
However, applications using this entitlement will be rejected during app review.
The extension is initialised with this code:
FIFinderSyncController.default().directoryURLs = [URL(fileURLWithPath: "/")]
How can I prevent this error to be thrown? I could use security scoped bookmarks, open a dialog and then save this bookmark. However, I have tested plenty of extension available in the App Store and none of them have shown any NSOpenPanel,
the files have been created without any problems.
Any help is appreciated.
The standard approach here is to have your container app present a file panel as part of the setup process. It then passes the security-scoped URL (or bookmark) to your Finder Sync extension. This serves two purposes:
-
The Finder Sync extension uses this to populate
directoryURLs
. -
The Finder Sync extension can save a security-scoped bookmark to retain long-term access to that directory (not just the directory, but the entire hierarchy rooted at that directory).
Oh, btw, this is worrying:
FIFinderSyncController.default().directoryURLs = [URL(fileURLWithPath: "/")]
Finder Sync extensions were not intended to be a general-purpose Finder extension mechanism. Rather, their intended purpose is stated in the name: The expected use case is that the Finder Sync extension own a directory, or small set of directories, that it syncs with some sort of cloud service. From a UI perspective, think iCloud Drive [1].
If you try to use a Finder Sync extension as a general-purpose Finder extension mechanism you will run into problems. For example, if you claim the entire file system starting at /
and then the user installs another Finder Sync extension that does the same, things end badly.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] Although iCloud Drive is not based on this technology.