Reputation: 2530
I'm working on a sandboxed OS X app where images get saved into a user-selected directory. There are two ways for the user to pick their output directory: selecting the directory using an NSOpenPanel, and dragging and dropping the directory onto the app.
When I use the drag/drop approach, everything works fine and my files get saved with no issues.
However, if I pick the directory using NSOpenPanel, I get error 513:
Error 513: "You don't have permission to save the file 'x.jpg' in the folder 'y'."
Both the NSOpenPanel and drag/drop code keep their chosen URL in the same place and process it in the same way. What could account for this difference? Does the NSOpenPanel have to be set up in a specific way to grant read/write permission to the directory?
For the record, I've never noticed this problem in the past year of using my app, so it might be a recent change to Cocoa — but I'm not 100% sure about that.
Upvotes: 3
Views: 688
Reputation: 16246
In my case, I was mistakenly writing my individual files to paths created by concatenating each filename to the URL:
panel.directoryURL
After changing that to:
panel.urls.first
...it worked. Hope this saves some headaches.
Upvotes: 0
Reputation: 2530
As expected, it looks like I was using NSOpenPanel wrong. 😐
Was storing URL from delegate call in panel(_ sender: AnyObject, validate url: URL)
. Should have been calling the panel's URL properties from the callback in begin(completionHandler handler: (Int) -> Swift.Void)
.
Upvotes: 3