Skip to main content
Bedazzled532
Inspiring
August 21, 2024
Question

Invoke a command using Indesign script

  • August 21, 2024
  • 4 replies
  • 859 views

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

4 replies

Inspiring
November 21, 2025

Recompose all stories?

app.menuActions.item("$ID/Recompose all stories").invoke();
leo.r
Community Expert
Community Expert
August 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.

Peter Kahrel
Community Expert
Community Expert
August 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.

Bedazzled532
Inspiring
August 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];

Peter Kahrel
Community Expert
Community Expert
August 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]);
}
brian_p_dts
Community Expert
Community Expert
August 21, 2024

You don't need a menu item. 

 

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

 

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

Bedazzled532
Inspiring
August 21, 2024

@brian_p_dts For some reason it is not working. 

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