title: Is there an alternative to NSFileCoordinator for opening related files in a sandbox?
body: <p>This is a follow-up to <a href="https://stackoverflow.com/q/14772480/560648">Access sidecar files in a Mac sandboxed app</a>.</p>
  
  <p>Though not covered in the answer there, the Apple docs teach us that to access a "related file" we must use an <code>NSFileCoordinator</code> for access (<a href="https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html" rel="nofollow noreferrer">ref</a>).</p>
  
  <p>This is a little heavy for my needs, and poses an architectural problem, since the actual file access is in my back-end code, away from the reaches of the Apple library facilities. I don't want to have to use the <code>NSFileCoordinator</code> for obtaining the related file's content, if I can help it. I don't want to require my users to manually identify the sidecar file either (if nothing else, this would be a bad workflow for batch processing). I just want to tell the sandbox "this is okay, this app can open such-and-such a related File.XYZ after the user chose File.ABC".</p>
  
  <p>For normal file accesses this isn't a problem: using an <code>std::ifstream</code> to <a href="https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_files_user-selected_read-only?language=objc" rel="nofollow noreferrer">open a file that's been previously selected from an Open panel</a> seems to work for remainder of the app instance's lifetime.</p>
  
  <p>But opening a "related file" seems to be more limited.</p>
  
  <p>Having added a <code>NSIsRelatedItemType</code> to my app's plist (as indicated in the linked answer), what is the minimal thing I can do in the front-end, presumably immediately after opening the "primary"/requested file, such that I can also later use an <code>std::ifstream</code> to open a related sidecar file? The documentation seems a little sparse on this subject&hellip;</p>
  
  <p>Perhaps my best bet is to perform a one-time prompt for the user to authorise access to the encapsulating directory, and save the resulting entitlement as an app-scoped bookmark (<a href="https://stackoverflow.com/a/48785789/560648">ref</a>) but again that's not quite as transparent as I'd like. It would also be perhaps a little "scary" for users to be confronted with such a request.</p>