OSX NSFileManager Error 513

I am developing a new OS-X App. When I try to save a file using an internally-generated file name based on the most-recently read file, I get Error 513. Saving to a file whose name comes from NSSavePanel works fine. What privilege is the App missing?

Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “2022-09-03.xml” in the folder “2022”." UserInfo={NSFilePath=/Volumes/HDD2/Documents/OS-X Apps/Polls/2022/2022-09-03.xml, NSUnderlyingError=0x600002765740 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

Does the "2022" folder exist?

Can you grant your app "Full Disk Access" in System Preferences? Sorry if that doesn't help, but it's late and I can't think of anything else.

When I try to save a file using an internally-generated file name based on the most-recently read file, I get Error 513.

Look at the underlying error. Code 1 in NSPOSIXErrorDomain is EPERM, meaning that this isn’t blocked but file system permissions but by the sandbox. Is your app sandboxed? If so, it won’t be able to save files at arbitrary paths.

For more on this general topic, see On File System Permissions.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

OSX NSFileManager Error 513
 
 
Q