Read and write permission for user selected folder in Mac OS app?
Add user-selected
and bookmarks.app
permissions in entitlement file :
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.files.bookmarks.app-scope</key>
<true/>
Then open folder selection using NSOpenPanel
so the user can select which folders to give you access to. The NSOpenPanel
must be stored as a bookmark and saved to disk. Then your app will have the same level of access as it did when the user selected the folder.
Is it bad practice to write to files in your application's .app folder?
Yes it is bad practice, for a number of reasons:
- macOS is a multi-user OS, and in general each user should have their own preferences, settings, etc.
- Users generally don't (and shouldn't) have file permissions to modify things in /Applications. If an admin user manually installed an app via drag-and-drop, they will have write access to it, but this can't be counted on (especially since, as I said, it's a multi-user OS and a different user may've installed it).
- If your app is code-signed, changes in the app container will break the signature and the app will refuse to open (it's considered damaged). Even it you don't sign it, the OS may apply an ad-hoc signature to it (for various reasons), and modifications will break that.
Related Topics
Cannot Invoke 'Filter' with an Argument List of Type '((_) -> _)'
Swift Mutable Set: Duplicate Element Found
Swift- Variable Not Initialized Before Use (But It's Not Used)
Why Is It Legal to Mutate an Actor's Nonsendable Property
Turn for in Loops Local Variables into Mutable Variables
Launch Sudo Command from MACos App Swift
Converting Swift 2.3 to Swift 3.0 - Error, Cannot Invoke 'Datatask' with an Argument List of Type'
Swift: How to Get Form Values Using Eureka Form Builder
My Uiviewcontroller Is Not Filling the Entire Screen
How to Access Firebase Variable Outside Firebase Function
Fblpromises Framework Not Found
How to Restrict a Protocol to Value Types Only
Swift 2.0 Keychain Type Errors for Secitemcopymatching
Is There a Daylight Savings Check in Swift
In Swift, How to Write a Generic Function to Resize an Array