1

I'm working on a Mac OS app and just ran into an interesting situation. As this is a file based app, users can drag and drop files and folders onto the app and they get added to an array and displayed in a list. They can also add files and folders via an NSOpenPanel.

When the file is added a lot of file variables get set, one of which is the save directory which is set to the same directory as the file.

Due to the App Sandbox, unless the user manually chooses a save directory (after the file has been added), even if it's the same directory that is already set for the file, I cannot write the export.

This app allows users to add a bunch of files and batch them all out at once, so requiring manual user interaction to set a save directory is cumbersome, especially if the user just wants to save out to the same directory as the original file they added.

I know I could request full disk access but I think that's very intrusive and there's really no reason this app needs that kind of permission. I don't want to be able to write anywhere, and I still want the user to be able to manually select a different save directory, but it would be helpful if they didn't have to manually select a save directory for every file, and the sandbox would allow the same directory as the original file to be written to.

So, long story short.....

I'm wondering if there is a solution to expanding the sandbox when a user adds a file, instead of only when they are saving the exported file?

mahal tertin
  • 3,239
  • 24
  • 41
kittonian
  • 1,020
  • 10
  • 22
  • Do you use the `URL` of the file or do you use paths? Do you want to save the file or do you want to add extra files in the same directory? Does your app have permission to write user selected files? – Willeke Jun 23 '23 at 16:38
  • I don't want to do anything other than grant sandbox permission to write files when the user adds a file, either by drag and drop onto the app, or by using an NSOpenPanel. The app already works just fine (i.e. I can write files as I mentioned in my post), I am only trying to determine if it's possible to improve the workflow so the user doesn't have to be prompted, since they are the ones that added the file(s) in the first place. – kittonian Jun 23 '23 at 16:49
  • You only have permission to access the user selected files. What do you want to write where? – Willeke Jun 23 '23 at 16:55
  • this is probably more a question of user experience than actual programming. there is somehow a possibility to save a file under the same name with another suffix. you could also save the directory in a security scoped bookmark and use this subsequently. – mahal tertin Jun 23 '23 at 17:18
  • Apparently I'm not explaining this very well. It doesn't matter though as it seems it's not possible anyway. I changed the workflow to prompt the user if the app doesn't have write permissions to the directory, instead of expecting the user to know to make a save directory selection. All good now. Thanks anyway. – kittonian Jun 23 '23 at 19:16

0 Answers0