19 Replies Latest reply on Dec 3, 2014 11:31 PM by vladan saveljic

    find specific hyphenated word

    vladan saveljic Level 4

      hello,

      is there a way to find all occurrences of one specific word, but only when it is hyphenated?

      Thank you in advance

       

      p.s I can see the answer(s) only tomorrow

        • 1. Re: find specific hyphenated word
          [Jongware] Most Valuable Participant

          Yes -- by making a list of all occurrences of that word (which is a built-in function), and then removing the ones that are not hyphenated (which is not, but pretty easy).

           

          Note that finding multiple words is a pretty useless operation. Usually you are interested in locating the first (or next) occurrence, or you want to find them then and then do something. A potential problem, however, is that 'doing something' to an hyphenated word may change the running text, and so words that were earlier reported as 'not hyphenated' could be broken, and the reverse.

           

          The following script will find all hyphenated occurrences of 'nonfunctional' ... and then do nothing with that information.

           

          app.findTextPreferences = app.changeTextPreferences = null;
          app.findTextPreferences.findWhat = "nonfunctional";
          app.findChangeTextOptions.wholeWord = true;
          
          list = app.activeDocument.findText();
          for (i=list.length-1; i>=0; i--)
              if (list[i].lines.length < 2)
                  list.splice(i,1);
          
          
          • 2. Re: find specific hyphenated word
            camilo umana Level 1

            Jongware,

             

            Very interesting script. I am very sure it will have many possibilities.

             

            IT is possible to use a list of words instead of only one?

             

            Thanks for this piece.

            • 3. Re: find specific hyphenated word
              [Jongware] Most Valuable Participant

              Put it in a loop. But its usefulness depends heavily on what you do with the words you find. Finding is okay, then having something automatically done not.

              • 4. Re: find specific hyphenated word
                vladan saveljic Level 4

                hi jongware,

                thanks a lot.

                However I do something wrong: I copied and pasted youre script. I changed the word "nonfunctional" with one other word (hyphenated) and when I start the script don't happened nothing.

                Where I wrong?

                Thanks in advance

                • 5. Re: find specific hyphenated word
                  [Jongware] Most Valuable Participant

                  Correct, and that's why I already said it would not 'do' anything after finding. But the script itself does work, and the variable list is filled with the found items; then the script stops. It's up to you to 'do' something with that list.

                   

                  What do you want to do with the found text? Let me remind you again that something like changing the found text will not work the way one would hope! As soon as you change any text, (1) it will most likely invalidate the rest of the 'found' list, because this stores text positions -- and when text re-formats, the earlier found positions may not be valid anymore; and (2) if the text re-formats, words that are in the list as "hyphenated" may reflow and not be hyphenated any longer, as well as words that are not in the list may be hyphenated.

                  • 6. Re: find specific hyphenated word
                    camilo umana Level 1

                    Jong,

                     

                    Your script could be magic and irreplaceable in cases where some partitions originate big problems.

                     

                    It is possible to change the finding of a word for an expression that finds hyphen-culo?

                     

                    For example, in spanish those words composed by the termination culo (culos) –that is literally ***/*****– are seen very bad when the hyphen shows it and the costume is fix them.

                    Without your script checking these words could be almost impossible as the termination culo/s is part of tens of thousands of words.

                    It is interesting this point as I am sure this termination is the only one that creates this alert.


                    70 copy.jpg

                    • 7. Re: find specific hyphenated word
                      vladan saveljic Level 4

                      Hi jongware,

                      For me is important that the script just find the hyphenated word, but when I start the script doesn't find nothing, although the hyphenated word exist.

                       

                      I have one file in indesign that has 600 pages and I have seen that one abbreviation sometimes hyphenated.

                      Now, I don't want change all occurrences with "find" that word and "change" in the same word but not hyphenated, because the text in this case could moves without my control.

                      I would like simply to find that word only when it is hyphenated and change manually with controll if the text moves or not.

                       

                      Thank you in advance

                      • 9. Re: Re: find specific hyphenated word
                        [Jongware] Most Valuable Participant

                        Okay, that's clear. Here is a longer script that (1) prompts you for the word (it'll remember the last one used, or use any selected text), (2) search for hyphenated occurrences as before, and (3) if found, highlight the next case. It will search through the entire document and start in the position the text cursor is in. It will start searching in the 'current' story and if it doesn't find the word in there, it will check all other stories (i.e., unconnected textframes).

                         

                         

                        if (app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline") && app.selection[0].contents.length > 0)
                           word = app.selection[0].contents;
                        if (word == undefined)
                            word = '';
                        wordToFind = prompt ("Find what", word);
                        if (wordToFind)
                        {
                            app.findTextPreferences = app.changeTextPreferences = null;
                            app.findTextPreferences.findWhat = wordToFind;
                            app.findChangeTextOptions.wholeWord = true;
                        
                            list = app.activeDocument.findText();
                            for (i=list.length-1; i>=0; i--)
                                if (list[i].lines.length < 2)
                                    list.splice(i,1);
                        
                            // found anything?
                            if (list.length == 0)
                                alert ("Cannot find match");
                            else
                            {
                                // anything selected?
                                if (app.selection.length == 0 || !(app.selection[0].hasOwnProperty("insertionPoints")))
                                {
                                    // no, pick first one
                                    list[0].select();
                                    app.layoutWindows[0].zoomPercentage = app.layoutWindows[0].zoomPercentage;
                                } else
                                {
                                    // locate next after current position
                                    for (i=0; i<list.length; i++)
                                    {
                                        if (list[i].parentStory == app.selection[0].parentStory)
                                        {
                                            if (list[i].insertionPoints[0].index > app.selection[0].insertionPoints[0].index)
                                            {
                                                list[i].select();
                                                app.layoutWindows[0].zoomPercentage = app.layoutWindows[0].zoomPercentage;
                                                break;
                                            }
                                        }
                                    }
                                    if (i==list.length)
                                    {
                                        // not in this story; anywhere else?
                                        for (i=0; i<list.length; i++)
                                        {
                                            if (list[i].parentStory != app.selection[0].parentStory)
                                            {
                                                list[i].select();
                                                app.layoutWindows[0].zoomPercentage = app.layoutWindows[0].zoomPercentage;
                                                break;
                                            }
                                        }
                                        if (i==list.length)
                                            alert ("Cannot find match");
                                    }
                                }
                            }
                        }
                        
                        • 10. Re: Re: find specific hyphenated word
                          [Jongware] Most Valuable Participant

                          Camilo, I think you could use a GREP style for that! Create a char style that has only No Break set, and apply it to

                           

                          \wculos?\b

                           

                          -- all words that end with 'culo' or 'culos' (good thing the Dirty Word Nanny Filter only complains about English words ) . The No Break will prevent breaking just before this part, but it will still break on other allowed positions.

                          • 11. Re: find specific hyphenated word
                            vladan saveljic Level 4

                            This script is exactly what I needed!

                            Thank you very much jongware

                            • 12. Re: Re: find specific hyphenated word
                              camilo umana Level 1

                              Jong,

                               

                              Yes, it works although frequency for this item is very high.

                              Visual control seems better as long words could be need breaking sometimes.

                              Thanks.

                               

                              Screen Shot 2014-12-03 at 07.54.32.jpg

                              • 13. Re: find specific hyphenated word
                                vladan saveljic Level 4

                                hi camilo umana,

                                very interesting

                                thank you

                                • 14. Re: Re: find specific hyphenated word
                                  camilo umana Level 1

                                  Hi. I understand the script asks for a word?

                                  1. if (word == undefined) 
                                  2.     word = ''
                                  3. wordToFind = prompt ("Find what", word); 

                                   

                                  JONG.jpg

                                  • 15. Re: find specific hyphenated word
                                    [Jongware] Most Valuable Participant

                                    Hmm ... I'm a bit busy now so can't check -- and this would require restarting ID a couple of times. I thought 'undefined' values (i.e., not earlier defined) had the contents "undefined". I think I did not notice because while writing "word' always was defined because of previous runs of the same script. Maybe you can add a try..catch around this?

                                    • 16. Re: find specific hyphenated word
                                      camilo umana Level 1

                                      Jong, something is curious  as premio_oscar admitted the script is working.

                                      Yes, of course I will check.

                                      Thanks for your time.



                                      • 17. Re: find specific hyphenated word
                                        vladan saveljic Level 4

                                        hi camilo umana,

                                        I select a word and than start the script.

                                        in this way the script doesn't give any error message.

                                        If I don't select nothing and start the script then I have the same error message as your.

                                        • 18. Re: find specific hyphenated word
                                          camilo umana Level 1

                                          Premio,

                                           

                                          Thanks.

                                           

                                          You may find P. Kahrel's scripts mentioned before also very interesting.

                                          For example, you get in a whistle a list like this:

                                           

                                           

                                          Kaka_nia

                                          illu_sion

                                          after_ward

                                          kill_ings

                                          with_in

                                          cul_tivated

                                          haphaz_ard

                                          uni_fying

                                           

                                          k2.jpg

                                           

                                           

                                          Modernism: Representations of National Culture - The man without qualities - Central European University Press

                                          • 19. Re: find specific hyphenated word
                                            vladan saveljic Level 4

                                            Thank you camilo for the Kahrel's script.