How to grant access to Users Documents folder?

How to grant access to Users Documents folder from a sandbox Xcode 11 macOS app. I want the app to be able to open an existing file (without using NSOpenPanel) in the users document directory. I have looked through the apple sandbox doc and don't see a way to do this.

How is this done?


Take a look at Security-Scoped Bookmarks. You can find a short description how they work in the last half of this document:
https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html

Nevertheless you have to ask for permission via NSOpenPanel for the file or the folder one time. Then you can persist the Security-Scoped Bookmark for future use.

Greetings
Brigitte
Thanks for the info. I see how to proceed.
Could you talk a little bit about why you want to open files in ~/Documents without the user having given prior permission? You wouldn't be able to enumerate the directory without access anyway?
How to grant access to Users Documents folder?
 
 
Q