Skip to main content
Inspiring
November 18, 2020
Answered

Activate open document by name using wildcard for the document name

  • November 18, 2020
  • 3 replies
  • 622 views

Hello,

I want to activate an open document by name.

The document  name always  start with "small_", ends with  different number for 1 to 31, extension .pdf

For example today opened document is "small_18.pdf"

There is a way to activate it by name using wildcard, eg "small_*" ?

 

This topic has been closed for replies.
Correct answer Manan Joshi

Try the following

for(var i = 0; i < app.documents.length; i++)
{
	var fName = app.documents[i].name
	if(fName.match(/small_\d+\.pdf/))
	{
		app.activeDocument = app.documents[i]
		break;
	}
}

-Manan

3 replies

Manan JoshiCommunity ExpertCorrect answer
Community Expert
November 18, 2020

Try the following

for(var i = 0; i < app.documents.length; i++)
{
	var fName = app.documents[i].name
	if(fName.match(/small_\d+\.pdf/))
	{
		app.activeDocument = app.documents[i]
		break;
	}
}

-Manan

-Manan
siomospAuthor
Inspiring
November 18, 2020

It is perfect,

thank you!

Community Expert
November 18, 2020

The question is not clear, do you mean to say there are lots of document open and want the script to activate the first document that matches your criteria? Why can't this be done manually, how will a script help?

-Manan

-Manan
siomospAuthor
Inspiring
November 18, 2020

Always there is only one open document starting with "small_x"
Usage example
The user open the "small_x.pdf" document

Then opens about ten or more documents

At every one of other documents, the user make a path selection

The script makes a copy of the selection, close the document, activates the "small_x.pdf" , and paste it

I hope it is clear now!

 

 

femkeblanco
Legend
November 18, 2020

What if there is more than one open document starting with "small_"?  Which should become active then?  

siomospAuthor
Inspiring
November 18, 2020

Always there is only one open document starting with "small_"