Skip navigation
MatthewWilliamsCMH
Currently Being Moderated

Find item then stop?

May 9, 2012 4:16 AM

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.

 
Replies
  • Currently Being Moderated
    May 9, 2012 5:16 AM   in reply to MatthewWilliamsCMH

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

     

    This will definitely take much time to find since it is finding all the words starts with a capital letter. Instead iterate every story and then by every line and then check the last word of each line.

     

    Green4ever

     
    |
    Mark as:
  • Currently Being Moderated
    May 9, 2012 5:23 AM   in reply to MatthewWilliamsCMH

    I have written a javascript to find all hypenated words, if you want you can use it, and here it is:

     

    http://forums.adobe.com/message/3699390#3699390

     

    Green4ever

     
    |
    Mark as:
  • Currently Being Moderated
    May 9, 2012 7:42 PM   in reply to MatthewWilliamsCMH

    MatthewWilliamsCMH wrote:

     

    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).

     

     

                 move selection to last character of item MyWord in MyFoundWords

     

    You can't move a selection; instead set the selection:

     

    set selection to last character of item MyWord in MyFoundWords

     

     

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points