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

Invoke a command using Indesign script

Enthusiast ,
Aug 21, 2024 Aug 21, 2024

There is a command to recompose all the stories. It is:

Ctrl + Alt + /

 

I want to invoke the same command using this method:

app.menuActions.item("$ID/Show Rulers").invoke();

 

Instead of "Show Rulers" how do I write the above command. 

Thanks

TOPICS
Scripting
814
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 ,
Aug 21, 2024 Aug 21, 2024

You don't need a menu item. 

 

app.activeDocument.stories.everyItem().recompose();

 

Though app.activeDocument.recompose() should work fine too

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
Enthusiast ,
Aug 21, 2024 Aug 21, 2024

@brian_p_dts For some reason it is not working. 

I have to run  Ctrl Alt / to refresh the stories.

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 ,
Aug 21, 2024 Aug 21, 2024

It is true that .recompose() doesn't always work. What sometimes helps is a good kick up the story's backside. The script version of the kick is to change the size of the story's first text frame, then set it back to the original. Something like this:

frame = myStory.textContainers[0];
gb = frame.geometricBounds;
// Make the frame 1 unit of whatever taller and wider
frame.geometricBounds = [gb[0], gb[1], gb[2]+1, gb[3]+1];
// Set it back to its original size
frame.geometricBounds = gb;

 Rattling a frame like this usually works.

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
Enthusiast ,
Aug 22, 2024 Aug 22, 2024

@Peter Kahrel Thanks for the reply.

I am getting error message on running the script:

"myStory is undefined".

 

I then added following line but to no avail:

myStory = app.activeDocument.stories;

 

After adding this line, I get following error message:

 

Error Number: 55
Error String: Object does not support the property or method 'textContainers'

Engine: main
File: C:\Users\shah\AppData\Roaming\Adobe\InDesign\Version 19.0-ME\en_AE\Scripts\Scripts Panel\recompose.jsx
Line: 15
Source: myframe = myStory.textContainers[0];

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 ,
Aug 22, 2024 Aug 22, 2024

Yes, sorry, 'myStory' was just a generic variable name.

 

Do myStory = app.activeDocument.stories[0] (if the document has one story).

Or select a text frame and do myStory = app.selection[0].parentStory

 

And to process all stories in a document, do

function processStory (aStory) {
  // Whatever
}

myStories = app.activeDocument.stories.everyItem().getElement();
for (i = 0; i < myStories.length; i++) {
  processStory (myStories[i]);
}
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
Enthusiast ,
Aug 22, 2024 Aug 22, 2024
LATEST

@Peter Kahrel Thanks a lot.

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 ,
Aug 21, 2024 Aug 21, 2024
quote

There is a command to recompose all the stories. It is:

Ctrl + Alt + /

By @Bedazzled532

 

In addition to other suggestions, you can, probably, invoke this very shortcut via a script. I know how it's done in AppleScript (which is useless for you) but not in JS, but it must be possible in JS too.

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