Skip to main content
13H
Inspiring
September 16, 2015
Answered

Sort character styles by name

  • September 16, 2015
  • 1 reply
  • 953 views

Hey guys,

Does anyone know how I can sort the paragraph styles of a document by name using Javascript?

(The same as choosing 'Sort by Name' in the paragraph style fly-out menu)

app.activeDocument.characterStyles.keys(list).sort(function(a,b){return list-list});

Thanks,

Bruno

This topic has been closed for replies.
Correct answer csm_phil

HI CoverBuilder,

Try the below JS lines, its execution the menu actions.

try{

    app.menuActions.item("$ID/Sort by Name").invoke();

    }catch (e){};

thx,

csm

1 reply

csm_phil
csm_philCorrect answer
Legend
September 16, 2015

HI CoverBuilder,

Try the below JS lines, its execution the menu actions.

try{

    app.menuActions.item("$ID/Sort by Name").invoke();

    }catch (e){};

thx,

csm

13H
13HAuthor
Inspiring
September 17, 2015

Thanks for your quick reply. I always forget the menu actions invoke!

Your solution works great. Only thing to note is that this will sort the paragraph styles as well.

Bruno

13H
13HAuthor
Inspiring
September 21, 2015

You can use itemByID to target Paragraph Style specifically.

There are multiple instances for Sort by Name available (Eg: Character, Object and Table styles).

If one of them is not available you get the "Action not enabled" error.

try{ 

    app.menuActions.itemByID(8505).invoke(); 

}catch (e){};