7 Replies Latest reply on Jun 29, 2010 5:22 AM by Harbs.

    Hyphenated words

    Oviya... Level 1

      Hai Friends,

       

                          How to Find Hyphenated words in InDesignCS4 file using java script.

       

      Thanks,

      Divya.

        • 1. Re: Hyphenated words
          tobias.wantzen Level 1

          Hi Divya,

           

          we once discussed this topic in for AppleScript. Here's the result, which can give you some hints for developing the JS-equivalent:

           

          set theList to {}

           

          tell application "Adobe InDesign CS4"

            tell document 1

           

               set theWords to object reference of every word of every story where baseline of character 1 is not baseline of character -1

               repeat with aWord in theWords

                  set firstLine to (every character of aWord whose baseline = baseline of character 1 of aWord) as string

                  set secondLine to (every character of aWord whose baseline = baseline of character -1 of aWord) as string

                  set end of theList to firstLine & "-" & secondLine

               end repeat

           

            end tell

          end tell

           

          return theList

           

          Greetings

          Tobias

          • 2. Re: Hyphenated words
            Oviya... Level 1


            Hai Tobias

                           Could you please give me the java script code for this hyphenate logic

             

            Thanks,

            Divya.

            • 3. Re: Hyphenated words
              Peter Kahrel Adobe Community Professional & MVP

              If a line does not end in a space then that line ends in a hyphenated word. Exceptions are lines that end in a return (last line in a paragraph) and lines ending in a dash.The quickest way to find hyphenated words (well, actually, divided words is what you're looking for) is this: create an array of lines, then check the last character of each line.This is lightyears quicker than comparing the baseline of the last word in one line and that of the word in the next line.

               

              For a scripted example of this approach, see Teus de Jong's script (http://www.teusdejong.nl/ then pick "InDesign utilities"), which collects all hyphenated words in a document and displays them in a window so you can find those words in the text by clicking in the displayed list; Martin Fischer has a script at http://tinyurl.com/2aretxq which is comparable to Teus's script in that it displays the hyphenated words in a window (using the baseline-comparison method); and there's a script at http://www.kahrel.plus.com/indesign/hyphenation.html which uses Teus's method but rather than displaying the hyphenated words, it dumps them in a new document;

               

              Peter

              • 4. Re: Hyphenated words
                PankChat Level 1

                Dear Peter,

                 

                I tried "gethyphens" script from the website but it throws error Unknown

                UI type "checkbox" at line 397. I will try to look into the reason later.

                I hope its works on IDCS3 (MAC).

                 

                cheers,

                --PC

                 

                 

                 

                 

                 

                 

                 

                Peter Kahrel <forums@adobe.com>

                06/29/10 03:08 PM

                Please respond to

                clearspace-9529900-639966-2-2933503@mail.forums.adobe.com

                 

                 

                To

                Pankaj Chaturvedi <pankaj.c@thomsondigital.com>

                cc

                 

                Subject

                Re: Hyphenated words

                 

                 

                 

                 

                 

                 

                 

                If a line does not end in a space then that line ends in a hyphenated

                word. Exceptions are lines that end in a return (last line in a paragraph)

                and lines ending in a dash.The quickest way to find hyphenated words

                (well, actually, divided words is what you're looking for) is this: create

                an array of lines, then check the last character of each line.This is

                lightyears quicker than comparing the baseline of the last word in one

                line and that of the word in the next line.

                 

                For a scripted example of this approach, see Teus de Jong's script (

                http://www.teusdejong.nl/ then pick "InDesign utilities"), which collects

                all hyphenated words in a document and displays them in a window so you

                can find those words in the text by clicking in the displayed list; Martin

                Fischer has a script at http://tinyurl.com/2aretxq which is comparable to

                Teus's script in that it displays the hyphenated words in a window (using

                the baseline-comparison method); and there's a script at

                http://www.kahrel.plus.com/indesign/hyphenation.html which uses Teus's

                method but rather than displaying the hyphenated words, it dumps them in a

                new document;

                 

                Peter

                • 5. Re: Hyphenated words
                  Harbs. Level 6

                  if(line.words[-1].lines.length>1){

                  //it's hyphenated

                  }

                   

                  Harbs

                  • 6. Re: Hyphenated words
                    Peter Kahrel Adobe Community Professional & MVP

                    Correct -- but slow.

                     

                    Peter

                    • 7. Re: Hyphenated words
                      Harbs. Level 6

                      Hmm.

                       

                      Your approach is very interesting.

                       

                      Here's what is probably the fastest way to using this method:

                       

                      contents = myStory.lines.everyItem().contents;
                      lineNumbers = [];
                      for(i=0;i<contents.length;i++){
                          switch(contents[i].charAt(contents[i].length-1)){
                              case " ":
                              case"\r":
                              case"\n":
                              case"-":
                                  break;
                              default:
                                  lineNumbers.push(i);
                                  break;
                          }
                      }
                      alert(lineNumbers);

                       

                      You can then loop through the lineNumbers to get the words:

                       

                      alert(myStory.lines[lineNumbers[0]].words[-1].contents);

                       

                      Harbs