Can’t open the same InDesign document twice
Short version:
I’m trying to open the same indesign file twice with the same function.
It works fine the first time, but fails without error message the second time.
I’m using InDesign CC 2022 on macOS.
// 1
var res = open_docs(["file.indd","~/Desktop/file.indd], true);
var the_doc = res[0];
// Read my IDs
the_doc.close(SaveOptions.NO);
// 2
var res = open_docs(["file.indd","~/Desktop/file.indd], false);
var the_doc = res[0];
// Update my IDs
the_doc.close(SaveOptions.YES);
function open_doc(docs_i, open_hidden) {
var this_doc_name = docs_i[0];
var this_doc_fullName = docs_i[1];
// Check if docs_i is open
var this_doc = app.documents.itemByName(this_doc_name);
if( this_doc.isValid &&
// ^ A document with the correct name is open, and ...
(this_doc.fullName.toString() == this_doc_fullName.toString())
// ^ the document has the correct path.
){
doc_open = true;
} else {
doc_open = false;
// open the document
this_doc = app.open(this_doc_fullName, true);
// this_doc = app.open(this_doc_fullName, !open_hidden);
// doesn’t get here, the second time this is run.
app.activeDocument = this_doc;
}
return [this_doc, doc_open];
}
Full story:
In a first step, I open all documents of a book and search for custom IDs (= Text in a text frame).
Each document is processed after the other. Before I open a document I check if it is already open.
Open documents stay open, all others are closed after processing.
In the second step I want to open the documents again and update the IDs.
I’m using the exact same function to open, but this time it fails before the document is opened.
The script doesn’t do anything after the line with open(), but I don’t get any error message.
In my test scenario (two small docs in a book) everything runs quite fast.
So I wonder, if it might have something to do with the file system.
Could it help, to open the document as a copy in step one?
Also: I’m running the function from a dialog (palette)
Thanks for any help / idea.
Regards, Martin
