Skip to main content
Known Participant
November 2, 2025
Answered

Indesign - script personnal order for object style

  • November 2, 2025
  • 2 replies
  • 81 views

Hello,

I am looking to write a script to rearrange my object styles (with much subgroups) according to a personal order.
Just a short example:

MY_PRINCIPAL_STYLE_HORIZONTAL
MY_SECOND_STYLE_HORIZONTAL
MY_PRINCIPAL_STYLE_VERTICAL
MY_SECOND_STYLE_VERTICAL​


In this specific case, I saw that it required :

  1. - renaming with a number 
002_MY_SECOND_STYLE_HORIZONTAL
001_MY_PRINCIPAL_STYLE_HORIZONTAL
004_MY_SECOND_STYLE_VERTICAL​
003_MY_PRINCIPAL_STYLE_VERTICAL
  • - then sorting by name
001_MY_PRINCIPAL_STYLE_HORIZONTAL
002_MY_SECOND_STYLE_HORIZONTAL
003_MY_PRINCIPAL_STYLE_VERTICAL
004_MY_SECOND_STYLE_VERTICAL​
  • - and then removing the number.
MY_PRINCIPAL_STYLE_HORIZONTAL
MY_SECOND_STYLE_HORIZONTAL
MY_PRINCIPAL_STYLE_VERTICAL
MY_SECOND_STYLE_VERTICAL​

With ChatGpt and Mate, I make three scripts for the moment.  I'm stuck on part 2 taken from this post. This code app.menuActions.itemByID(113168).invoke();  doesn't always seem to execute correctly on each run.

I use Indesign 2021 in my work. Is there a better way to invoke this action?

Correct answer Laubender

Hi @RYR9 ,

to sort object styles by name you could also use this menu action:

app.menuActions.itemByName( "$ID/SortObjectStylesName" ).invoke();

 

However, you could first check if the menu action is available (enabled) in the context you are using it:

var mA = app.menuActions.itemByName( "$ID/SortObjectStylesName" );

if( mA.enabled )
{
mA.invoke();
}
else
{
alert( "ERROR: " + mA.name + "is currently not enabled." )
};

 

Kind regards,
Uwe Laubender
( Adobe Community Expert )

2 replies

Legend
November 2, 2025

Some panels with lists or trees allow a selection of multiple items.

Some panel associated menu actions will consider such a panel selection, or within a contextual click the hit item, and work on that. They require that the panel is open and that there is such a selection.

You can't simulate the effect via a scripted invoke(). Fallbacks might work on every item or give up.
I do not know whether this is the case for your menu actions, but your "doesn't always seem" sounds like that.

 

Alternatively you (or your AI) could try the myObjectStyle.move(LocationOptions.…,parentOrSibling) method, it should work without the panel.

LaubenderCommunity ExpertCorrect answer
Community Expert
November 2, 2025

Hi @RYR9 ,

to sort object styles by name you could also use this menu action:

app.menuActions.itemByName( "$ID/SortObjectStylesName" ).invoke();

 

However, you could first check if the menu action is available (enabled) in the context you are using it:

var mA = app.menuActions.itemByName( "$ID/SortObjectStylesName" );

if( mA.enabled )
{
mA.invoke();
}
else
{
alert( "ERROR: " + mA.name + "is currently not enabled." )
};

 

Kind regards,
Uwe Laubender
( Adobe Community Expert )