Highlighted

Sort by Name via script

New Here ,
Oct 20, 2009

Copy link to clipboard

Copied

Hi everybody,

I would appreciate if someone could give some clue to sort by name the

Paragraph Styles, Character Styles, Object Styles and Swatches panels

via script.

Thank you all in advance.

Edson Furman

edsonfurman@terra.com.br

Adobe Community Professional
Correct answer by Peter Kahrel | Adobe Community Professional

For sorting styles I have used the script listed below -- works in CS3 and CS4 though it's been a while since I last tried. It could be coded more elegantly but it always worked fine as it is. It doesn't take into account any style groups -- I don't know what happens if your documents contain any so you'd better not try.

As to swatches, these are not so easy to sort. There was some discussion about this at either of these sites:

http://www.hilfdirselbst.ch/gforum/gforum.cgi?jump=forum%3D4

http://indesign-faq.de/

Peter

#target indesign

sort_par_styles (app.documents[0]);
sort_char_styles (app.documents[0]);
sort_obj_styles (app.documents[0]);

//-------------------------------------------------------------------------------

function sort_par_styles (doc)
    {
    var string_array = sort_par_names (doc);
    for (var i = 0; i < string_array.length; i++)
        doc.paragraphStyles.item (string_array).move (
            LocationOptions.after, doc.paragraphStyles[i+2])
    }

function sort_par_names (doc)
  {
  var array = doc.paragraphStyles.everyItem().name;
  array.shift (); array.shift ();  // exclude [No p.] and [Basic p/]
  return array.sort (case_insensitive);
  }

//-------------------------------------------------------------------------------

function sort_char_styles (doc)
    {
    var string_array = sort_char_names (doc);
    for (var i = 0; i < string_array.length; i++)
        doc.characterStyles.item (string_array).move (
            LocationOptions.after, doc.characterStyles[i+1])
    }

function sort_char_names (doc)
  {
  var array = doc.characterStyles.everyItem().name;
  array.shift ();  // exclude [None]
  return array.sort (case_insensitive);
  }

//-------------------------------------------------------------------------------

function sort_obj_styles (doc)
    {
    var string_array = sort_obj_names (doc);
    for (var i = 0; i < string_array.length; i++)
        doc.objectStyles.item (string_array).move (
            LocationOptions.after, doc.objectStyles[i+4])
    }

function sort_obj_names (doc)
  {
  var array = doc.objectStyles.everyItem().name;
  array.shift (); array.shift (); array.shift ();  array.shift (); // exclude  [None], [Basic Graphics Frame], [Basic Text Frame], [Basic Grid]
  return array.sort (case_insensitive);
  }

//-------------------------------------------------------------------------------

function case_insensitive (a, b)
  {
  return a.toLowerCase() > b.toLowerCase()
  }
TOPICS
Scripting

Views

1.1K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Sort by Name via script

New Here ,
Oct 20, 2009

Copy link to clipboard

Copied

Hi everybody,

I would appreciate if someone could give some clue to sort by name the

Paragraph Styles, Character Styles, Object Styles and Swatches panels

via script.

Thank you all in advance.

Edson Furman

edsonfurman@terra.com.br

Adobe Community Professional
Correct answer by Peter Kahrel | Adobe Community Professional

For sorting styles I have used the script listed below -- works in CS3 and CS4 though it's been a while since I last tried. It could be coded more elegantly but it always worked fine as it is. It doesn't take into account any style groups -- I don't know what happens if your documents contain any so you'd better not try.

As to swatches, these are not so easy to sort. There was some discussion about this at either of these sites:

http://www.hilfdirselbst.ch/gforum/gforum.cgi?jump=forum%3D4

http://indesign-faq.de/

Peter

#target indesign

sort_par_styles (app.documents[0]);
sort_char_styles (app.documents[0]);
sort_obj_styles (app.documents[0]);

//-------------------------------------------------------------------------------

function sort_par_styles (doc)
    {
    var string_array = sort_par_names (doc);
    for (var i = 0; i < string_array.length; i++)
        doc.paragraphStyles.item (string_array).move (
            LocationOptions.after, doc.paragraphStyles[i+2])
    }

function sort_par_names (doc)
  {
  var array = doc.paragraphStyles.everyItem().name;
  array.shift (); array.shift ();  // exclude [No p.] and [Basic p/]
  return array.sort (case_insensitive);
  }

//-------------------------------------------------------------------------------

function sort_char_styles (doc)
    {
    var string_array = sort_char_names (doc);
    for (var i = 0; i < string_array.length; i++)
        doc.characterStyles.item (string_array).move (
            LocationOptions.after, doc.characterStyles[i+1])
    }

function sort_char_names (doc)
  {
  var array = doc.characterStyles.everyItem().name;
  array.shift ();  // exclude [None]
  return array.sort (case_insensitive);
  }

//-------------------------------------------------------------------------------

function sort_obj_styles (doc)
    {
    var string_array = sort_obj_names (doc);
    for (var i = 0; i < string_array.length; i++)
        doc.objectStyles.item (string_array).move (
            LocationOptions.after, doc.objectStyles[i+4])
    }

function sort_obj_names (doc)
  {
  var array = doc.objectStyles.everyItem().name;
  array.shift (); array.shift (); array.shift ();  array.shift (); // exclude  [None], [Basic Graphics Frame], [Basic Text Frame], [Basic Grid]
  return array.sort (case_insensitive);
  }

//-------------------------------------------------------------------------------

function case_insensitive (a, b)
  {
  return a.toLowerCase() > b.toLowerCase()
  }
TOPICS
Scripting

Views

1.1K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 20, 2009 0
Adobe Community Professional ,
Oct 20, 2009

Copy link to clipboard

Copied

For sorting styles I have used the script listed below -- works in CS3 and CS4 though it's been a while since I last tried. It could be coded more elegantly but it always worked fine as it is. It doesn't take into account any style groups -- I don't know what happens if your documents contain any so you'd better not try.

As to swatches, these are not so easy to sort. There was some discussion about this at either of these sites:

http://www.hilfdirselbst.ch/gforum/gforum.cgi?jump=forum%3D4

http://indesign-faq.de/

Peter

#target indesign

sort_par_styles (app.documents[0]);
sort_char_styles (app.documents[0]);
sort_obj_styles (app.documents[0]);

//-------------------------------------------------------------------------------

function sort_par_styles (doc)
    {
    var string_array = sort_par_names (doc);
    for (var i = 0; i < string_array.length; i++)
        doc.paragraphStyles.item (string_array).move (
            LocationOptions.after, doc.paragraphStyles[i+2])
    }

function sort_par_names (doc)
  {
  var array = doc.paragraphStyles.everyItem().name;
  array.shift (); array.shift ();  // exclude [No p.] and [Basic p/]
  return array.sort (case_insensitive);
  }

//-------------------------------------------------------------------------------

function sort_char_styles (doc)
    {
    var string_array = sort_char_names (doc);
    for (var i = 0; i < string_array.length; i++)
        doc.characterStyles.item (string_array).move (
            LocationOptions.after, doc.characterStyles[i+1])
    }

function sort_char_names (doc)
  {
  var array = doc.characterStyles.everyItem().name;
  array.shift ();  // exclude [None]
  return array.sort (case_insensitive);
  }

//-------------------------------------------------------------------------------

function sort_obj_styles (doc)
    {
    var string_array = sort_obj_names (doc);
    for (var i = 0; i < string_array.length; i++)
        doc.objectStyles.item (string_array).move (
            LocationOptions.after, doc.objectStyles[i+4])
    }

function sort_obj_names (doc)
  {
  var array = doc.objectStyles.everyItem().name;
  array.shift (); array.shift (); array.shift ();  array.shift (); // exclude  [None], [Basic Graphics Frame], [Basic Text Frame], [Basic Grid]
  return array.sort (case_insensitive);
  }

//-------------------------------------------------------------------------------

function case_insensitive (a, b)
  {
  return a.toLowerCase() > b.toLowerCase()
  }

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 20, 2009 0
New Here ,
Oct 20, 2009

Copy link to clipboard

Copied

Great, Peter! Very thank you!

Edson

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 20, 2009 0
Enthusiast ,
Feb 11, 2017

Copy link to clipboard

Copied

An easiest way to do that...

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

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

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

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

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

It will sort styles (character, paragraph, object, cell and table) by name.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 11, 2017 2
Contributor ,
Oct 15, 2020

Copy link to clipboard

Copied

@lf.corullon 

Are there itemByID(**numbers here**) for Swatches too ??

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 15, 2020 0
Enthusiast ,
Oct 15, 2020

Copy link to clipboard

Copied

No. To sort swatches, scripting is much more complex.

Thanks for Justin, from Ajar Productions, we have a free script for this.

https://ajarproductions.com/blog/2013/12/13/sort-swatches-in-adobe-indesign/

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 15, 2020 1
Contributor ,
Oct 15, 2020

Copy link to clipboard

Copied

Thanks a ton!  🙂

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 15, 2020 0
Contributor ,
Oct 15, 2020

Copy link to clipboard

Copied

It turns out this was too long ago to be compatible.  I tried to just open the installers and see the script code to be able to make it a jsx but no such luck.  

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 15, 2020 0
Enthusiast ,
Oct 16, 2020

Copy link to clipboard

Copied

It is still compatible.

It is a jsx file.

When you download the zip, try to rename the zxp file extension to zip and then open it. The jsx file is there.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 16, 2020 1
MadMac55 LATEST
Contributor ,
Oct 16, 2020

Copy link to clipboard

Copied

Worked nicely.  Thank you for that tip.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 16, 2020 0