5 Replies Latest reply: May 10, 2012 7:25 AM by MatthewWilliamsCMH RSS

    Find item then stop?

    MatthewWilliamsCMH

      Hi Everyone

       

      I'm pretty inexperienced at Applescript, though I know VBA pretty well and understand (more or less) the concepts of scripting.

       

      I'm trying to write an Applescript for InDesign that will find an auto-hyphenated word that begins with a capital letter, select it, then terminate so I can evaluate whether or not I'll allow the word to hyphenate. (This would be a variation of the FindHyphens.jsx script, the additional parameter of the cap--and I hope, speed--being the main differences.)

       

      I'm having a couple problems: 1) After the first execution, I get this error: "Adobe InDesign CS4 got an error: Missing required parameter 'to' for event 'move'." (See below; as you can se, I have a parameter for the "to" event). I can only clear the error by closing the script and reopening it. (I'm running it from Applescript Editor, not from InDesign's script palette.) 2) The script works fine on a very short document—three paragraphs with two lines of dummy text in each—but in a real document that is more than 300 pages long, the script never seems to stop or produce any results. I've waited 20 minutes and finally had to force quit it.

       

      I think item 1 is just a logical problem that I will eventually figure out, but I think item 2 is more serious. If I understand correctly, find grep (see below) compiles an array of all the items in the object--in my case, the document--that meet the search criteria before proceeding to the next step. Is that correct? Is there any way to change that behavior so that it just scans through the document beginning at the cursor and looking forward until it finds the next match?

       

      Here is my code (forgive how klunky it is; I'm new to this):

       

      tell application "Adobe InDesign CS4"

        set find grep preferences to nothing

        set change grep preferences to nothing

        set find what of find grep preferences to "\\u[a-z’]+"

        set MyFoundWords to find grep

        repeat with MyWord from 1 to count of MyFoundWords

            set i to baseline of first character of item MyWord in MyFoundWords

            set j to baseline of last character of item MyWord in MyFoundWords

                          if i is equal to j then

                   move selection to last character of item MyWord in MyFoundWords

                          else

                   select item MyWord in MyFoundWords

                   set find grep preferences to nothing

                   set change grep preferences to nothing

                   exit repeat

               end if

                end repeat

      end tell

       

      Thanks for any help.

       

      m.