11 Replies Latest reply on Feb 21, 2016 8:49 PM by karthiks94217840

    Auto-hyphen identifier

    selvam214 Level 1


      If we have any special character to find the auto-hyphen for the end of line?



          if(myFound[i].lines[0].characters[-1].contents == 'special character for auto-hyphen')


      Screen shot 2015-01-02 at 12.25.12 PM.png

        • 1. Re: Auto-hyphen identifier
          Chinnadk Level 4

          Try this,


          var doc = app.activeDocument,  
              _stories = doc.stories;  
          for(var i=0;i<_stories.length;i++)  
                  var _lines = _stories[i].lines;  
                  for(var j=0;j<_lines.length;j++)  
                          if(_lines[j].words[-1].lines.length >=2)




          • 2. Re: Auto-hyphen identifier
            selvam214 Level 1

            Hi Chinna,


            I truly appreciate for this solution and your help in resolving the problem (both).




            • 3. Re: Re: Auto-hyphen identifier
              Peter Kahrel Adobe Community Professional & MVP

              This is an interesting problem and makes an appearance in this forum every now and then. It's interesting because the solution seems simple, but it's more complicated than it it seems. Also, finding auto-hyphenated words is one of the better examples of how dramatic speed improvements can be gained by tweaking the code. There's a script that the late Teus de Jong and I wrote that collects and displays all auto-hyphenated words; it's here: http://www.kahrel.plus.com/indesign/get_hyphens.jsx. That script shows a very quick method of collecting divided words.


              Chenna's script has some interesting problems (I mention this not as a criticism, but because the problem is illustrative): it breaks on tables; if a hyphenated word is the last word of a paragraph, that word is listed twice; it doesn't ignores footnotes; and because of the repeated calls to the line object, the script is slow. The first problem is fixed by changing line 8 as follows:


              if(_lines[j].words.length > 0 && _lines[j].words[-1].lines.length >=2)


              Lines/paragraphs that consist of a table do not contain any words (just a single character, the table). The second problem is trickier. You don't want words that already contain a hyphen, only auto-hyphenated words. And you don't want words followed by en en-dash, em-dash. So the lines you're interested in are those that do not end in a space, a hyphen, an en- or em-dash, or any paragraph break. See the script linked above for details.


              Finally, most scripts can be sped up enormously by placing InDesign's objects in one or more arrays rather than processing the objects as they are. Chenna's script takes about 220 seconds to process a text that contains 1250 lines, which in turn contain about 75 hyphenated words. A modified version processes the same text in 3 seconds:


              words = app.documents[0].stories.everyItem().lines.everyItem().words[-1].getElements();
              for (i = words.length-1; i >= 0; i--) {
                  if (words[i].lines.length > 1) {
                      $.writeln (words[i].contents);


              The speed gain is in the first line: the script creates one array consisting of the last word in every line. (This script, too, finds the last hyphenated word of a paragraph twice, and skips footnotes).



              • 4. Re: Re: Auto-hyphen identifier
                Chinnadk Level 4

                Thanks for the detailed explanation, Peter.

                • 5. Re: Auto-hyphen identifier
                  MadMac55 Level 1

                  I think I could use a script like this to generate a list of hyphenation exceptions for a custom dictionary.  My question is ... does it look at the entire list of words in the text frame that are indeed auto-hypenating?  If someone was to import a wordlist from a custom dictionary and shrink the columns to force auto-hyphenation (wildly), would the script return a recommendation based on the content or based on what is showing prior to overset?  Because to do this correctly, you are going to shrink column width until you get overset and catch 95% of the auto-hyphenation.


                  Am I making sense?  This would be a very effective tool in capturing a hyphenation exceptions list.

                  • 6. Re: Auto-hyphen identifier
                    Peter Kahrel Adobe Community Professional & MVP

                    You could use either of or all three scripts described here:


                    • 7. Re: Auto-hyphen identifier
                      MadMac55 Level 1



                      Reading this is like Worship Hour.  :-)  The pure science behind what you, de Jong and Fischer did -- well, I just find amazing. Down to every detail, too.  My son is a freshman at Univ of Washington.  He's writing Javascript and beyond, but I need to show him this work to make a point  of relevance to community and simply amazing code.  My hat goes off to you and your colleagues.


                      • 8. Re: Auto-hyphen identifier
                        karthiks94217840 Level 2

                        HI Chinnadk,


                        Hi chinna, i am new in InDesign Java Script. Please guide me


                        I need your help chinna. How to find paragraphs line end, continue 3 hyphen words by java script.


                        Advance thanks china,

                        • 9. Re: Auto-hyphen identifier
                          karthiks94217840 Level 2

                          Dear friends,


                          Hi all java expert,


                          Please clarify my above problem by indesign Cs6. this help saved my life, help my friends,


                          Advance Thanks All.

                          • 10. Re: Auto-hyphen identifier
                            Level 1



                            Please change the hyphenation limit in the paragraph style. It will avoid the there consecutive hyphenation in the file.





                            • 11. Re: Auto-hyphen identifier
                              karthiks94217840 Level 2

                              HI sreekarthik,


                              Thanks your good replay seekarthik.


                              Already i now this change the hyphenation limit in the paragraph style. But, I need to control in the java script by indesign file Cs6.


                              This is posible to control the java script? please suggest me sreekarthik.