Read and Write Permission for User Selected Folder in MAC Os App

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



Leave a reply



Submit