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

Activate open document by name using wildcard for the document name

Engaged ,
Nov 18, 2020 Nov 18, 2020

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

 

TOPICS
Scripting
494
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 , Nov 18, 2020 Nov 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

Translate
Adobe
Guide ,
Nov 18, 2020 Nov 18, 2020

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

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

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

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
Community Expert ,
Nov 18, 2020 Nov 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

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

 

 

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
Community Expert ,
Nov 18, 2020 Nov 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

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

It is perfect,

thank you!

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