AppleScript `export` ignores which document it is sent to

Viewed 4

Marked 3.2.14 (1232), Mac App Store, macOS 26.5 (via Claude Code)

With several documents open, export always exports the first document in the list, whichever document the script names. I had four documents open, in this order: closetestA.md (just opened), board-update-2026-09-28.md, marked-share-table-test.md, and status.md. Each of these three commands wrote a PDF of closetestA.md, and the three PDFs were byte-for-byte the same size:

tell application "Marked" to tell document "board-update-2026-09-28.md" to export paginated pdf to POSIX file "/tmp/a.pdf"
tell application "Marked" to tell document 3 to export paginated pdf to POSIX file "/tmp/b.pdf"
tell application "Marked" to tell (first document whose name is "board-update-2026-09-28.md") to export paginated pdf to POSIX file "/tmp/c.pdf"

The specifiers themselves resolve correctly: get name of document 3 returns marked-share-table-test.md. It is only export that ignores the target. Earlier in the same session, an export addressed to marked-share-table-test.md produced a PDF of board-update-2026-09-28.md, which was document 1 at that moment.

This matters for scripts because the wrong document is exported without any error. My workaround is to open the file immediately before exporting, since a newly opened file becomes document 1, and to export document 1.

I couldn't tell whether export uses the first document in the list or the frontmost window, since in every test the first document was also the one most recently opened. What I'd expect is that tell document X to export ... exports document X.

1 Answers

Thanks for the detailed report, Mark. You were exactly right: export ignored the document it was sent to and exported the frontmost document instead. The cause was in Marked's scripting dictionary. The export commands didn't declare a direct parameter, so the tell document ... target never reached them. The same problem affected other document commands like get_statistics, marked link, and refresh preview. Those silently returned missing value when sent to a specific document.

I've fixed it for the next update. tell document "name", tell document 3, and tell (first document whose ...) will all act on the document you name. You'll also be able to write it as a direct parameter:

tell application "Marked" to export paginated pdf document "board-update-2026-09-28.md" to POSIX file "/tmp/a.pdf"

Until then, your workaround of opening the file right before exporting document 1 is the most reliable approach.