I'm working on a C++ program in Xcode, which opens some files in the project folder, which is in ~/Documents/Xcode Projects
. Because it's in my Documents folder, every time I run the program, it asks for permissions to access my documents folder, and I have to click yes every time. I tried explicitly giving the program permission in the settings, and that works for a little bit, but after about 3 runs of the program it asks for permissions again. Can I just disable the document folder protection? How?
How to disable Documents folder protection
catalinafinderpermissionxcode
Related Question
- How to disable Xcode’s ‘“ProjectName” is a project downloaded from the Internet. Are you sure you want to open it?’ dialog
- MacOS – give read&write permission to only 1 file in folder
- MacOS – Extend Catalina’s privacy protection to other folders
- Mac – How to prevent iCloud from downloading (storing) certain files in an Xcode project in iCloud
- MacOS – How to add/remove applications from “File and Folders” inside “Security and Privacy” -> Privacy Tab
- MacOS – Giving an app permissions to the documents folder without admin
- Spotlight can’t open a folder inside ~/Documents/
Best Answer
The easy way is to turn off sandboxing for the app, in Xcode project settings under "capabilities". You might not want that though.
Otherwise you probably need a security-scoped bookmark to the directory. When you get access, create a bookmark from the directory URL using
bookmarkData(options:includingResourceValuesForKeys:relativeTo:)
. Make sure to use.withSecurityScope
in theoptions
argument. Save that to user defaults. Then when you want to use the directory,init(resolvingBookmarkData:options:relativeTo:bookmarkDataIsStale:)
with options of[.withSecurityScope, .withoutUI]
..startAccessingSecurityScopedResource()
before trying to use the URL..stopAccessingSecurityScopedResource()
when you're done with the URL.