App access to chosen file's parent directory

I have an app that needs access to the directory containing the file opened by the user. The workflow for creating a new app document is:


  • user selects a .plist file with info related to the new document
  • app calculates path of another folder with data files next to that .plist file
  • app calculates path of new app document
  • user reviews info, clicks "Continue" button
  • app reads .plist, creates new app document, reads data files


On Catalina, the .plist can be read, because it was selected via NSOpenPanel. The additional folder can't be accessed, and the new app document can't be created, presumably because they weren't selected via NSOpenPanel. The file exists in a ~/Development/ subdirectory and does not trigger a permissions request to access the directory. The same problem occurs if the directory is accessed via network share (end users will always use a network share).


Is there any way to enable this functionality on Catalina without requiring users to enable full disk access? This is a business workflow app so enabling full disk access isn't a big problem, but if there's a way to get permission to access other items in the parent directory of the chosen file I'd rather just do that.


On a side note, a different app (not a Cocoa app) that creates that .plist has been granted access to the Documents folder, and is able to create that .plist file which is not in the ~/Documents folder without any permissions promps. That app does require the user to select a directory a couple levels above where the .plist is created. Does selecting a directory via NSOpenPanel grant implicit permissions to all subdirectories?


edit: the app is not a sandboxed app.


Jim Crate

Replies

So I figured out the problems. I was using NSString's stringByAbbreviatingWithTildeInPath (for display purposes) and then calculating the other paths from that. On my development machine, since I installed Catalina I had to move my development directory, so it was now at /Users/me/Development instead of /Development. So stringByAbbreviatingWithTildeInPath was actually altering the path now, and previously I never tested in my home directory.


When running the app in Xcode, it was translocating the path, i.e. the ~ was being substituted with the app path in the debug folder. Once I updated the code to not use stringByAbbreviatingWithTildeInPath it worked fine.


And when I tested using a VM to work with a network share, it was not logging in so the whole network share was read-only. Once I fixed that it worked fine with the network share too.


Jim Crate