• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Javascript to check if a named indd is already open

Contributor ,
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

185

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

Community Expert , 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

Votes

Translate

Translate
Community Expert ,
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

Votes

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
Contributor ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

LATEST

Thanks, Mark. That's great.

Votes

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