Highlighted

Activate open document by name using wildcard for the document name

Explorer ,
Nov 18, 2020

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_*" ?

 

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Scripting

Views

57

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

Activate open document by name using wildcard for the document name

Explorer ,
Nov 18, 2020

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_*" ?

 

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Scripting

Views

58

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
Nov 18, 2020 0
Engaged ,
Nov 18, 2020

Copy link to clipboard

Copied

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

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
Reply
Loading...
Nov 18, 2020 0
Explorer ,
Nov 18, 2020

Copy link to clipboard

Copied

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

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
Reply
Loading...
Nov 18, 2020 0
Adobe Community Professional ,
Nov 18, 2020

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

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
Reply
Loading...
Nov 18, 2020 0
Explorer ,
Nov 18, 2020

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!

 

 

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
Reply
Loading...
Nov 18, 2020 0
Adobe Community Professional ,
Nov 18, 2020

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

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
Reply
Loading...
Nov 18, 2020 1
siomosp LATEST
Explorer ,
Nov 18, 2020

Copy link to clipboard

Copied

It is perfect,

thank you!

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
Reply
Loading...
Nov 18, 2020 0
Resources