Skip to main content
Bedazzled532
Inspiring
Aug 21, 2024 10:06 AM UTC
Question

Invoke a command using Indesign script

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

8 replies

Legend
Nov 21, 2025 9:44 AM UTC

Recompose all stories?

app.menuActions.item("$ID/Recompose all stories").invoke();
Translate
leo.r
Community Expert
Community Expert
Aug 21, 2024 9:19 PM UTC
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
Peter Kahrel
Community Expert
Community Expert
Aug 21, 2024 5:47 PM UTC

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
Bedazzled532
Inspiring
Aug 22, 2024 1:16 PM UTC

@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
Peter Kahrel
Community Expert
Community Expert
Aug 22, 2024 1:44 PM UTC

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
brian_p_dts
Community Expert
Community Expert
Aug 21, 2024 2:44 PM UTC

You don't need a menu item. 

 

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

 

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

Translate
Bedazzled532
Inspiring
Aug 21, 2024 4:14 PM UTC

@brian_p_dts For some reason it is not working. 

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

Translate