Skip to main content
Inspiring
June 11, 2022
Answered

Javascript to check if a named indd is already open

  • June 11, 2022
  • 1 reply
  • 408 views

Hi all,

I'm trying to sort out this bit of code that checks if a named file is open in InDesign. When the indd isn's open it's throwing an error.

Error String: Object is invalid

if( app.documents.itemByName(" RH KEEP ME.indd").visible == true ) 
{
	alert("Found it");
	}
else
{
	alert("Not found");
}

What have I gone and done this time?

Many thanks in advance if you can help.

This topic has been closed for replies.
Correct answer m1b

Hi @JustyR, this is how I would do it:

var myTargetDoc = app.documents.itemByName(" RH KEEP ME.indd");

if (myTargetDoc.isValid) {
    alert("Document is open.");
}
else {
    alert("Document isn't open.");
}

- Mark

1 reply

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
June 11, 2022

Hi @JustyR, this is how I would do it:

var myTargetDoc = app.documents.itemByName(" RH KEEP ME.indd");

if (myTargetDoc.isValid) {
    alert("Document is open.");
}
else {
    alert("Document isn't open.");
}

- Mark

JustyRAuthor
Inspiring
June 12, 2022

Thanks, Mark. That's great.