Copy link to clipboard
Copied
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_*" ?
1 Correct answer
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
Explore related tutorials & articles
Copy link to clipboard
Copied
What if there is more than one open document starting with "small_"? Which should become active then?
Copy link to clipboard
Copied
Always there is only one open document starting with "small_"
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
It is perfect,
thank you!

