Fractale
Fractale

Reputation: 1654

Unable to Create Files Adjacent to User-Selected File Due to App Sandbox Permissions

I am developing a macOS app that requires the ability to create new files in the same directory as a user-selected file, but I am encountering permission issues due to the App Sandbox restrictions. While the user can select a file (e.g., a.jpg) using a standard open panel, I cannot create an adjacent file (e.g., a.jxl) in the same folder because the sandbox only grants access to the selected file, not to other files in the directory.

I understand that full disk access might be an option, but it requires user intervention and isn't suitable for this case. Is there any way to extend access to other files in the directory (including those not selected by the user) while remaining within the App Sandbox environment?

Upvotes: 1

Views: 39

Answers (2)

mahal tertin
mahal tertin

Reputation: 3414

If your App just creates files with the same name as the selected one but with different extension, you may use the so called related file access NSIsRelatedItemType to extends your app’s sandbox to give your app access to the supporting file.

Otherwise let the user select the directory where to store the new files and persist the security scope as described in documentation: Persist access to files with security-scoped URL bookmarks

Upvotes: 1

Ujjwal Pathak
Ujjwal Pathak

Reputation: 11

The App Sandbox restricts access to only the file explicitly selected by the user, which can make it challenging to create adjacent files in the same directory. However, you can work around this limitation by using security-scoped bookmarks to extend access to the directory containing the selected file.

Upvotes: 1

Related Questions