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

Javascript to check if a named indd is already open

Contributor ,
Jun 11, 2022 Jun 11, 2022

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
394
Translate
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

Translate
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

Translate
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
LATEST

Thanks, Mark. That's great.

Translate
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