Character styles sort by name

Hey guys,.

Is anyone know how can I sort the paragraph styles to a document by its name using Javascript?

(The same as choosing "Sort by name" in the paragraph style menu drop-down)

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

Thank you

Bruno

HI CoverBuilder,

Try the Sub lines JS, executing actions from the menu.

try{
    app.menuActions.item("$ID/Sort by Name").invoke();
    }catch (e){};

THX,

CSM

Tags: InDesign

Similar Questions

  • CS3: need script to replace spaces with underscores in the paragraph and character style names

    Help! I am very new to scripting.

    I managed to find and tweak existing javascripts to search through all my paragraph styles to disable hyphenation and off balance the jagged lines, but I need help with this one.

    I work on Mac OS 10.4.11 using Indesign CS3.

    I need a script that will search all my paragraph and character styles in my open Active document and replace spaces by underscores.

    Can someone help me with this? It would be greatly appreciated!

    1. I don't know, but I think you can use all the regular GREP inside this function codes. Do not use the quotation marks around of the expression, use slashes! (Why? Just a curiosity of Javascript... maybe a hack that goes back to the gray mist of JS development...)

    This work should - but rather the code above, this is not tested:

    .. Replace (/ [-\ / ()-. _] + / g. '_');

    The GOLD group inbetween the brackets contain all the characters you want to replace with an underscore: the hyphen (this has to be the first character in the group, else it will be interpreted as a range of characters from each side!), space, slash (this one is 'special' inside the function replace JavaScript, so I think he needs to escape with a backslash)! in parentheses, a period (not sure if it should escape - into ordinary GREP, it's the wildcard character for any character, but maybe he loses his magic within a group of GOLD) and finally... the underscore character. Why?

    Well, this replacement string comes with a free bonus. Note the sign after the installment of GOLD +. This means that a whole sequence of these characters is replaced by a simple underscore: "it's / a - / test" will become "This_is_a_test". Adding the underscore line itself to the string of research means that it will also find the whole chain 'space space (stroke underscore)' in 'This style (_)' and, oh magic!, replace it immediately with a single underscore.

    Just FYI, the tiny "g" after the closing slash is abbreviation of 'global', i.e. at the global level, replacing in this string. replace the default values for a replacement only (why? see above...), and adding the 'g' ensures he keeps replacing until it is not find matches more.

    2 see point 1.

    3. uh, yes it's true, but you will need to check very carefully if nothing inside one of these basic models is substituted. You can apply a base style and add substitutions to make look like a subtitle, but that isn't making it a. And to the next paragraph, you can apply a base style and add substitutions to make it look like a paragraph of plain text (etc.). It's a signature of witness to bad formatting...

  • Sort by name via the script

    Hello world

    I would be grateful if someone could give some clues to sort by name from the

    Paragraph Styles, character Styles, Styles of object and panels color chart

    via the script.

    Thank you in advance.

    Edson Furman

    [email protected]

    To sort the styles I used the script below - works in CS3 and CS4 if it has been awhile since I finally tried. It could be coded with more elegance, but it worked well as it is. He does not account groups of style: I don't know what happens if your documents contain a sort you would better try.

    As for shades, these are not so easy to sort. There was a discussion about this at one 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[i]).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[i]).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[i]).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()
      }
    
  • Character styles do not work in Pages

    I'm on a MacBook Pro (13-inch, mid-2014, retina), running 10.10.5 (14F1021) and run pages v. 5.6.1

    It's pretty simple: I'm searching the internet apple documentation and Web sites.

    To the title of the pane 'format' to the right of the workspace, there is an option below 'police' called 'Styles of character ".  There is no way, in this latest version, to create a new character style.  No selection there will allow you to press the symbol '+', and there is no menu in the menu bar you option to create a character style.

    Despite trying several ways of dozens to understand this point, there is no work around.  I think it's a bug.

    Please fix this Apple?  I love the pages, but boy, this can be frustrating.

    Thank you!

    I use Pages on El Capitan 10.11.1 v5.6.1. I can define a character style.

    Try the following:

    1. Type a word or two. Select them.
    2. Press command + T to launch the Panel font
    3. In the toolbar, click the selector bar and in this menu, choose color
      1. Choose red
      2. Unique, choose the menu bar (you now have a single, red strikethrough)
    4. Selected always your text
      1. Click Character Styles picker
      2. The + symbol is now blue
        1. Click on + to add
        2. Change the new name of red bar, then press return to set.
      3. Click on any character Style
      4. Click the character crossed Red style to test.

    If you want any style of character custom for later use, you will need to make a custom template for new documents, or simply a model of style that you can open separately and then using the Format menu, styles of copy/paste between your model as well as the current document.

  • Add numbers of sequential endnote using a character style

    Hello

    I wonder if anyone knows of a script that could insert numbers of endnote sequentially to each instance of a character style.

    Our editing process, we use 'hard' note numbers that are based on numbers of items of the text. When the editing process is finished, we go through and manually change the sequential numbers. The endnote numbers have a special character style, so such a script would go to the first instance of this style of character, replace the characters by '1', then go to the next occurrence of the character style and replace the characters by '2' and so on.

    Any help would be appreciated.

    Alicia Dole

    A standard operation. In the third line, replace "number of hard endnote" with the name of the character style that you use for notes end.

    app.findGrepPreferences = null;
    app.findGrepPreferences.findWhat = '\\d+';
    app.findGrepPreferences.appliedCharacterStyle = 'Hard endnote number';
    found = app.documents[0].findGrep();
    for (i = found.length-1; i >= 0; i--) {
      found[i].contents = String (i+1);
    }
    

    Peter

  • best judgment for paragraph styles, object styles and character styles

    I want to learn the criteria difference and use of paragraph styles, object styles and character styles. I know how to use them, but know about the best judgment and context, when you use would be better. Can anyone recommend links? I've been using adobe. Please don't suggest books.

    Paragraph styles are whole paragraphs.

    Character styles are letters or isolated words. Do not use the long of an entire paragraph. Do not set all the attributes, only those who are different for the properties of the paragraph Style. Unlike Quark Xpress, in InDesign are character Styles used only for the difference of isolated words.

    Paragraph styles can include the character automatically Style: Styles, GREP, nested Styles, initial letters, chips automatic & numbers and line styles.

    Object styles , set the frame of the object. They include separate definitions of all of the object, the stroke and fill.

    Object styles can also be applied to images in a frame and groups.

    Object styles may also include in the following paragraph Style and a style of paragraphs in automatic way.

    Object styles have several categories, you can choose which category is relevant to apply. For example, it is possible to apply the first style object to give the stroke and fill and apply a different object style to format the corners only and then apply the next. (With this method last only the applied object Style is linked).

    Styles of the opportunity to make global changes in a document. If you build in a smart way, they are a huge time saver. They can be stored in the CC libraries or libraries with objects that are applied to them. If you have created once these styles, you can use them again, and with one or two clicks, you can make their own to new document.

    My recommendation: the habit of Styles, name them always with the same names that it helps you to be accustomed to them and to work faster, much faster.

    There are more models: Table Styles, Styles of cell, the Master Pages and color chart.

  • GREP style - apply character style to the opening and closing parentheses surrounding a 0 (but not 0)

    Hello

    I'm relatively new to GREP style and will have to put in shape about 600 postcards containing various data (via the merger of data), including phone numbers. Consider the following data set:

    1. + 44 (0) 123467800

    2 (©) copyright

    3. (name of the program)

    I want to tell Indesign to stagger the opening and the closing parenthesis of the baseline (with a character style), but only the bracket that include a 0 and, possibly, without affecting the 0 value between them.

    Seems like an easy task, but it is impossible to find a solution. Could someone help?

    Thank you very much

    Antonio

  • Table of contents, problems in applying the character style

    Hi all

    This is my first post, I checked if there was already something similar, but I can't find anything so I'm asking here.

    I work with Indesign 9.3 and I created a book of 80 pages and there are 20 + chapters.

    I wanted to create a table of contents, so I made an and I put my paragraph for her style, but I had problems to set the character style (he set only to the number of the page, but not to the number and the name of the chapter).

    When I create my summary style I have no problem to indicate the paragraph style that you want to use (and then it automatically applies it properly when I generate my list).

    The problem I want to solve, is that I need that my table of contents automatically the value of the character style, cause, for the moment, I have to apply it after its generation.

    Sorry for my bad English, I hope you understood

    Concerning

    Filippo

    In this case you must use the character for numers style nested within the paragraph style

    I'm usually two independent sparagraph styles (primary materials) chapters and sections (toc details). In this way, you can add a different same nested character style to stand them.

    Addibn later - style, it is not good idea. After the update of the table of contents, you have lost the

    macpawel

  • The different paragraph of distinct character style formatting

    Hello

    In my paper, I have bunch of paragraphs and each begins with the name (two or three words). Character style is applied to each name. Now, I want to add the paragraph after each name of each mark is so in its own paragraph. Of course, I can do it manually, hitting enter after each name, but I was wondering if there is a more efficient way through search/replace or perhaps GREP.

    Thank you!

    m

    Try this on a copy to be sure, but I think finding ^. + and set the format to find the character style, and then change to $0, you can also set the change of any character Style Format and a new paragraph Style that is applied by the character style formatting.

    This will probably leave you with a space at the end of the paragraph, or the beginning of the next. The location will depend on if the style is applied to the space. If this is the end of the paragraph, you can use find find ^(.+) (\s) and change to $1

    If it's at the beginning of the next paragraph, in my opinion, you need a second query, Find ^ /s (leave find it empty format or the value initially attributed the paragraph style) and do not fill the field exchange.

  • How to add a character style in the active document

    Hi experts

    How to create a character style in the active document.

    How to make the script work.

    Thank you

    Respect of

    John

    var myCharacterStyle;

    myDocument var = app.activeDocument;

    var myCharacterStyle = myDocument.characterStyles.add({name:"c"});)

    myCharacterStyle.strikeThru = true;

    myCharacterStyle.strokeColor = 'Black ';

    myCharacterStyle.add)

    There is not much to say about your code. Only the last line would cause a problem. A possible hiccup is also on the fact that the style may already exist when you want to add.

    myDocument var = app.activeDocument;

    var myCharacterStyle = myDocument.characterStyles.item ('c');

    ! myCharacterStyle.isValid & myCharacterStyle = myDocument.characterStyles.add({name:"c"});)

    myCharacterStyle.strikeThru = true;

    myCharacterStyle.strokeColor = 'Black ';

  • Is it possible to update a character style with the changes I made to the selected text?

    I use InDesign CS5 on OS X Yosemite.

    I don't really know the best way to put it, so I hope that this scenario makes sense.

    Let's say I have a document with a few styles of different characters, and on one page of the document, I decided that I would try something different for a title that has an applied character style - this style is applied to all titles at the same level on the rest of the document. I do not adjust the style of character, however, but simply adjust the setting in shape in the upper character Panel. After playing for awhile, I have decide that I'm really this new setting in shape and want to apply as a result of the document, but now I don't have a character for this style.

    I know that I could just make a new style of form the title I have changed, then go back into the rest of the document and apply it to other styles. However, since this title still has the original style applied (just with overrides), I would like to know if there is a quick way to update the style based on the new formatting?

    I hope that makes sense.

    Thank you for your help in advance.

    With the substituted text still selected (you will see a + next to the character name of the Style in the character Styles Panel), choose the Style to redefine in the character Styles Panel menu.

  • Character styles does not indent

    I tried to create a few simple lists of names with recessed contact information but the character Style I created does not want to add the dash that I specified in the details of the text. The original lines I've used has the dash, but I had to manually add the dash on others, designed with the same style.

    Short answer. Use a paragraph style.

    It is generally quite rare to use styles character to Muse. In the vast majority of cases you want consistent formatting of an entire paragraph, so a paragraph style is used. Character styles are for formatting a range of sub in a paragraph, usually for emphasis. However, on the web these ranges sup pointed out are almost always hyperlinks, so they are formatted with a style hyperlink rather than a character style. So in the end, paragraph styles are extremely common and useful, as are the hyperlink styles, but character styles are quite rare.

  • Need to search and apply a character style sheet

    I have a directory with the name and address of the student. I need to find 2 returns and replace with 2 returns, apply the character style, back. Here is a screenshot so you can see what I mean screen.

    [Picture with private information removed by Moderator]

    Allen, Davis must be condensed ital "BOLD" like Ahmed, Ehsan is above. Any help appreciated.

    Post edited by: Peter Spier

    Right. I have the impression that there is. As always... may be wrong.

  • find character styles

    Hello

    How to find styles of characters via javascript

    search for text by using the character style, the code below will do...

    app.findGrepPreferences = app.changeGrepPreferences = null;

    app.findGrepPreferences.appliedCharacterStyle = "char_style"; name of style //character

    found = app.activeDocument.findGrep (true);

    for (i = 0; i< found.length;="">

    Found [i]. Select();

    }

    app.findGrepPreferences = app.changeGrepPreferences = null;

    Vandy

  • CS5: Hyperlink to anchor text in the character style?

    Is it possible to script the following:

    A text has several occurrences of the same string, for example "A10". One is marked with a character style "Anchor" and others are marked by a character style "link." The idea is to create anchors text style "Anchor" then find all occurrences of the character 'Link' style and create a hyperlink to the corresponding anchor.

    I managed to find a script that creates a character style "Anchor" text anchors Can anyone offer suggestions on how to make script creating the links?

    Written by Kasyan Servetsky

    March 13, 2011

    // http://www.Kasyan.HO.com.UA

    / / e-mail: [email protected]

    //======================================================================================== =================================

    If (app.documents.length == 0) ErrorExit ("Please open a document and try again.");

    const gScriptName = "create anchor text."

    const gScriptVersion = "1.0";

    gDoc var = app.activeDocument;

    If (! gDoc.characterStyles.item("Anchor").isValid) ErrorExit ("Character style \"Anchor\"n'existe No.");

    CreateDestinations();

    //======================================================== FUNCTIONS  =====================================================

    function CreateDestinations() {}

    app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;

    app.findGrepPreferences.findWhat = '. '. + » ;

    app.findGrepPreferences.appliedCharacterStyle = gDoc.characterStyles.item ("Anchor");

    var found = gDoc.findGrep ();

    var destCounter = 0;

    for (var j = finds.length - 1; j > = 0; j-) {}

    var found = found [j];

    try {}

    If (! gDoc.hyperlinkTextDestinations.itemByName (found.contents) .isValid) {}

    var hypTextDest = gDoc.hyperlinkTextDestinations.add (found);

    hypTextDest.name = found.contents;

    destCounter ++;

    }

    }

    {catch (e)}

    }

    If (destCounter == 0) {}

    Alert ("no anchor text were created.", gScriptName + "-" + gScriptVersion);

    }

    Else if (destCounter == 1) {}

    Alert ("a text anchor is created.", gScriptName + "-" + gScriptVersion);

    }

    ElseIf (destCounter > 1) {}

    Alert (destCounter "text anchors have been created.", gScriptName + "-" + gScriptVersion);

    }

    }

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

    function ErrorExit (error, icon) {}

    warning (error, gScriptName + "-" + gScriptVersion, icon);

    Exit();

    }

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

    Hello

    The path is:

    create a hyperlinkTextDestination;

    create a hyperlinkTextSources;

    Create hyperlinks using a single destination and sources;

    so:

    // to create hyperlinks alike:    one destination==>many sources
    // destination is the 1st occurrence of text with charStyle "anchor" applied
    // sources are each occurrences of text with charStyle "link" applied
    
    var mDoc = app.activeDocument;
    
    app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
    app.findTextPreferences.appliedCharacterStyle = mDoc.characterStyles.item("anchor");
    
    var
         mAnchor = mDoc.findText()[0],
         mDest;
    
    if (mAnchor) mDest = mDoc.hyperlinkTextDestinations.add(mAnchor,{name: mAnchor.words[0].contents});
    else {alert ("no anchor found"); exit(); }
    
    app.findTextPreferences.appliedCharacterStyle = mDoc.characterStyles.item("link");
    
    var
         mSource = mDoc.findText(),
         len = mSource.length,
         currSource, currHyper;
    
    if (!len) {alert ("no link found"); exit(); }
    
    while (len-->0) {
         currSource = mDoc.hyperlinkTextSources.add(mSource[len],{name: "sourceLink_" + len});
         currHyper = mDoc.hyperlinks.add(currSource, mDest, {name: "mHyperlink_" + mDest.name + "_" + len});
         }
    
    app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
    

    Jarek

Maybe you are looking for