AppleScript cannot close a document

Viewed 11

Marked 3.2.4 (1218), Mac App Store, macOS 26.5 (via Claude Code)

close document 1 errors with -1708. The document class has no close in the dictionary. close window "name" returns success but the document stays in the app's document list and comes back on the next launch.

This means a script that opens files has no way to close them. With NSQuitAlwaysKeepsWindows on, documents accumulate across sessions. After enough pile up, I've seen File ▸ Publish… grey out for a valid document; quitting and relaunching fixes it immediately.

The workaround is to raise each new window via AXRaise and click File ▸ Close through System Events. Keystroke ⌘W fails silently; only the menu item works.

Either close on document or close window actually releasing the document would fix this.

2 Answers

You're right. close document was missing from the dictionary, and close window reported success without actually releasing the document. That's why files piled up across launches with window restoration on, and it's a likely reason Publish greyed out until a quit.

The next build will accept:

tell application "Marked"
	close document 1
end tell

close window will also close the document, not just the window. close all already worked and stays as-is.

Sorry that took a System Events workaround in the meantime.

Hi, I confirmed this fixed in 3.2.14 (1232). close document "name.md" runs without error and removes the document from the document list, close window "name" now closes the document too, and after a quit and relaunch nothing I had closed came back. My script now uses close document instead of the System Events workaround. Thank you!