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

Script to run app.menuActions on all open documents

Community Beginner ,
Sep 19, 2024 Sep 19, 2024

Copy link to clipboard

Copied

I need to run a couple menuActions on a batch of documents and I'm not sure if what I've done is correct or if maybe there's a more common way to do it. Here's my script:

 

 

for (var i = 0; app.documents.length > i; i++) {
    sortByName();
    app.activeDocument = app.documents[1]; //go to the next document
}    

function sortByName() {
    app.menuActions.itemByID(8505).invoke(); //sort p-styles
    app.menuActions.itemByID(8511).invoke(); //sort c-styles
}

 

 

This will sort all the paragraph and character styles alphabetically in all open documents. It seems to work just fine, but I'm not sure about that 3rd line.

 

I'm familiar with processing documents by their index, like app.documents[i].blahblah, but in this case, that app.menuActions would just run those menuActions over and over on the activeDocument. I need to make each document active one-by-one to run the app.menuActions, but once I've changed the activeDocument, obviously the index numbers change and my "i" value is wrong. 

 

My solution was to just run the function, then make the next document the activeDocument, over and over as many times as there are open documents. 

 

Is that a reasonable solution? Or is there some better/more common way to do this?

 

Thanks!

TOPICS
Scripting

Views

725

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
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 20, 2024 Sep 20, 2024

@Donald32516386092f 

 

Push names of open documents into an array - then loop through this array and use string from the element to "activate" document.

 

Votes

Translate

Translate
Community Expert ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

Names could be risky if two docs with the same name in two different locations were opened. 

Votes

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
community guidelines
Community Expert ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

quote

Names could be risky if two docs with the same name in two different locations were opened. 


By @brian_p_dts

 

Only if you store just the Name - not the FullName.

 

Votes

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
community guidelines
Community Expert ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

But then getByName doesn't work

Votes

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
community guidelines
Community Expert ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

quote

But then getByName doesn't work


By @brian_p_dts

 

How about just app.documents.item()? 

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Documents.html#d1e55803__d1e55957

 

Votes

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
community guidelines
Community Expert ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

quote

But then getByName doesn't work


By @brian_p_dts

 

And there is no getByName? 

 

Your search returned no results for GetByName

 

I think you meant itemByName? 

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Documents.html#d1e55803__d1e56023

 

Votes

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
community guidelines
Community Expert ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

LATEST

Oops. Been doing more Illustrator scripting lately (which uses getByName, stupidly)

Votes

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
community guidelines
Community Expert ,
Sep 27, 2024 Sep 27, 2024

Copy link to clipboard

Copied

Also, I'm 99.99% sure, I think I've tried this before, that if you try to open document that is already open - you won't get an error but reference to already open instance. 

 

Votes

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
community guidelines