Javascript to check if a named indd is already open

Participant ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

60

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Jun 11, 2022 Jun 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

Likes

Translate

Translate
Adobe Community Professional ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

LATEST

Thanks, Mark. That's great.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines