11 Replies Latest reply on Aug 17, 2014 9:59 AM by pixxxel schubser

    Script to find word stacks in InDesign

    sandy8000 Level 1

      CS6, InDesign -- I've been looking for a proofing script that finds word & letter stacks and highlights items found & would be easily removed once items have been reconciled.

        • 1. Re: Script to find word stacks in InDesign
          Pickory Level 3

          Hello,

           

          What is a word / letter stack?

           

          P.

          • 2. Re: Script to find word stacks in InDesign
            sandy8000 Level 1

            Hi P

             

            Three or more of the same word or characters stacked at the beginning or ending of lines.

             

             

             

            sj

            • 3. Re: Script to find word stacks in InDesign
              Sajeev Sridharan Level 4

              While this scripting forum is a great place to get scripting help, it's also very easy to misuse it. Please bear in mind that for most (if not all) of the participants here, writing scripts is a source of income. If someone writes a particularly useful script, don't be shy to offer money (privately)! Also, please do not expect that complete scripts will be written for you (although in many cases they will be). If you are a novice scripter and show an interest in learning, you will generally find that the help you recieve will be much more positive.

               

              Here's a short list of "Dos" and "Don'ts" to keep in mind...

               

              Do ask for help in automating your work in InDesign, but Don't expect a full solution for free.

               

              Do show an interest in learning, and people will probably try to help you, butDon't ask for other people to solve all your problems for you.

               

              If you need a script written for you, Do ask if someone is available to write one for pay, but Don't keep such an issue on the forum. Work it out off the forum please.

               

              Please Do thank others who spend the  time to solve your issues, and pleaseDon't expect every issue to be solved on a public forum. Many solutions have  taken a lot of programming time to work out, and it's not reasonable to  expect such solutions to be given away for free.

               

              Please Do give code examples to help other people, but please Don't pass off others code as you own!

               

              Please Do make a note in the topic of a new thread of what language you are using as well as the version number that you are using such as: [JS][CS3].

               

              Please Don't branch off a discussion in the middle to a new topic -- please start a new one!

               

              Please Don't start two discussions on one topic -- it makes it very confusing!

              • 4. Re: Script to find word stacks in InDesign
                sandy8000 Level 1

                Thanks for the list vandy, I’m not expecting a personalized script. Found one couple of years ago & can no longer locate it.

                • 5. Re: Script to find word stacks in InDesign
                  Sajeev Sridharan Level 4

                  I will guide you to solve your requirements, this is just a logic you have to create your own code...

                   

                  1) Create a loop for all the pages in your document  //for loop

                  2) Create a loop for all the textframes in each page  //for loop

                  3) Then create a loop for all the lines in each textframes  //for loop

                  4) Then store the last word of first line in a variable  //var declaration

                  5)Store the last word of second line a variable  //var declaration

                  6) Check the two words are equal  //if condition

                  7) if the words are equal -> store the last word of third line in a variable  //var declaration

                  8) Then check the third line last versus second line last word...  //if condition

                  9) If true, you got the result, words are stacked for three lines  //if condition

                   

                  Vandy

                  • 6. Re: Script to find word stacks in InDesign
                    Laubender Adobe Community Professional & MVP

                    And I want to add: If you are working in a long, threaded text with long paragraphs that is going from page to page, correcting one occassion of a stacked word can lead to unstacking of other found incidents or can lead to more stacked words on other places. This is depending on what you will do after finding one stack. If you can manage to correct one problem without adding or removing a line of text, you should be fine. Provided you are using the single-line paragraph composer. If not, be prepared that the situation will change above and below the found word stack inside one single paragraph.

                     

                    Stacked words are a moving target.

                    Not to mention letters stacked.

                     

                    Uwe

                    • 7. Re: Script to find word stacks in InDesign
                      pixxxel schubser Level 5

                      Hi sandy8000,

                      use can use e.g. these Greps in a FindChangeByList script.

                      GrepFindStacks.png

                       

                      For the same words at the beginning of paragraph:

                      ^(\w{2,}\b )\1+

                      --> with an space after \b

                       

                      For the same letters at the end:

                      ( \w)\1+(?=[[:punct:]]?$)

                      --> with an space before \w

                       

                      Have fun

                       

                      • 8. Re: Script to find word stacks in InDesign
                        Pickory Level 3

                        Hello,

                         

                        I think Sandy is looking vertically stacked words.

                         

                        Quite a challenge in a script, I think.

                         

                        I can see how can be done from a C plugin though.

                         

                        P.

                        • 9. Re: Script to find word stacks in InDesign
                          Dirk Becker Level 4

                          Taking challenges ...

                          @Pickory: did you think of a custom preflight rule? Happy programming!

                           

                          The following script selects the first word of a sequence of three at the end of consecutive lines.

                          For my laziness it lumps all stories together so you might run into rare cross-story cases.

                           

                          var w = app.activeDocument.stories.everyItem().lines.everyItem().words.lastItem().getElements();

                          for( var i=0; i<w.length-2; i++ ) {

                            if( w[i].contents==w[i+1].contents && w[i].contents==w[i+2].contents ) {

                            app.select(w[i]);

                            break;

                            }

                          }

                           

                          Dirk

                          • 10. Re: Script to find word stacks in InDesign
                            Pickory Level 3

                            Pix,

                             

                            Your Grep is very clever.

                             

                            Dirk,

                             

                            I like your solution. I think I was over complicating the problem.

                             

                            P.

                            • 11. Re: Re: Script to find word stacks in InDesign
                              pixxxel schubser Level 5

                              Hi sandy8000,

                               

                              for your question

                              Three or more of the same word or characters stacked at the beginning or ending of lines.

                              this should works for you (use a character style with a different color):

                              //FindChangeDoublesAtBeginAndEnd.jsx
                              app.findGrepPreferences = app.changeGrepPreferences = null;
                              
                              app.findGrepPreferences.findWhat = '^(\\w+ )\\1+\\b';
                              app.changeGrepPreferences.changeTo = '';
                              app.changeGrepPreferences.appliedCharacterStyle = 'Your predefined character style';
                              app.changeGrep();
                              
                              app.findGrepPreferences.findWhat = '( \\w+)\\1+\\b(?=[[:punct:]]?$)';
                              app.changeGrepPreferences.changeTo = '';
                              app.changeGrepPreferences.appliedCharacterStyle = 'Your predefined character style';
                              app.changeGrep();
                              
                              app.findGrepPreferences = app.changeGrepPreferences = null;
                              
                              
                              
                              

                               

                              Grep_FindStack_CS_5_5_script.png

                               

                              Have fun

                               

                               

                              If not, give us a text example, please.