1 Reply Latest reply on Oct 9, 2008 1:14 AM by Thomas B. Nielsen

    [CS2/CS3 JS] Finding the first character of each paragraph


      Can anybody help with my script below:

      for (h=0; myParaCount>h; h++){
      myChars = myStory.paragraphs.item(h).contents;
      if (myChars.characters.item(0) == "l" && myChars.characters.item(0).appliedCharacterStyle == CharStyleWin){
      myStory.paragraphs.item(h).appliedParagraphStyle = "L-B";

      This script is supposed to test if the first character is an "l" with my character style "Wingdings" applied to it. I could not test whether the character style is "Wingdings" or not. What could be wrong with my script. Thanks.
        • 1. Re: [CS2/CS3 JS] Finding the first character of each paragraph
          Thomas B. Nielsen Level 3
          // You need to have a textFrame selected
          var myFrame = app.selection[0];
          var myParaCount = myFrame.paragraphs.length;

          // There must exist a paragraphStyle name L-B
          var myApplyStyle = app.activeDocument.paragraphStyles.item("L-B")

          for (h=0; h < myParaCount; h++){
          var myChar = myFrame.paragraphs.item(h).characters.firstItem();
          // check if first char is "l" and if its applied charstyle name is CharStyleWin
          if (myChar.contents == "l" && myChar.appliedCharacterStyle.name == "CharStyleWin"){
          myFrame.paragraphs.item(h).appliedParagraphStyle = myApplyStyle;

          /* Edited at 11.21 */