My standard approach would be to try creating the security-scoped bookmark and see if that fails. I’m presuming that you tried that. What went wrong?
Thanks Quinn! Yepp, that's the first thing I tried. It produces a console error:
Scoped bookmarks can only be created for existing files or directories
Type: Error | Timestamp: 2025-11-18 14:10:18.411061+01:00 | Process: tst_manual_sandboxed_file_access | Library: CoreServicesInternal | Subsystem: com.apple.FileURL | Category: scoped | TID: 0xdd7936
and the bookmarkDataWithOptions call fails with an NSError:
Error Domain=NSCocoaErrorDomain Code=260 "Scoped bookmarks can only be created for existing files or directories" UserInfo={NSURL=file:///Users/torarne/write-single-file2.txt, NSDebugDescription=Scoped bookmarks can only be created for existing files or directories}
Which led me to using [NSURL checkResourceIsReachableAndReturnError:] before saving the bookmark.
And in turn this forum topic to determine if that's the right approach to handle this use-case, or if fileExistsAtPath is preferred :)
My worry is that fileExistsAtPath might produce false negatives, where checkResourceIsReachableAndReturnError would have returned YES. On the other hand, checkResourceIsReachableAndReturnError is less specific of why it would fail, when it fails.