1 Reply Latest reply on May 2, 2009 6:48 AM by [Jongware]

    Process Indesign Grep Search

    low Jackson

      Hi

       

      I'm using the following script, to search for fixture times within an InDesign Document.

       

       

      Unformatted InDesign text would be…

      Monday 19 March

      Gates 1.23 am First 4:56pm   Last RACE 7.12pm

       

       

       

      Applescript is:

       

      tell application "Adobe InDesign CS3"

       

         --Clear the Find/Change fields

         set find text preferences to nothing

         set change text preferences to nothing

       

         --Set FindWhat/ChangeTo values

         set find what of find grep preferences to "(\\n|\\r)[Gg][\\u\\l ]+(\\d+)[.:](\\d+)[\\u\\l ]+(\\d+)[.:](\\d+)[\\u\\l ]+(\\d+)[.:](\\d+)[\\l\\u]+"

         set change to of change grep preferences to "$1Gates Open $2.$3am First Race $4.$5pm Last Race $6.$7pm"

       

         --set the find options

         set include footnotes of find change grep options to false

         set include hidden layers of find change grep options to false

         set include locked layers for find of find change grep options to false

         set include locked stories for find of find change grep options to false

       

         --Do It

         change grep

       

         set find grep preferences to nothing

         set change grep preferences to nothing

       

      end tell

       

       

       

      This is working for me as a clean up on the structure and formatting, however I would now like to process the AM and PM based on the times (Rule all First & Last Race times will always be PM, Gates Open can be both)

       

       

      What I'm thinking is to get the times grep returns, query them, then set Am or PM to the string depending on the result.

       

      My problem!

       

      When I "return find grep preferences"

       

      I get this...

      {text from character 16 to character 61 of story id 191 of document "Gates Grep.indd" of application "Adobe InDesign CS3", text from character 16 to character 66 of story id 379 of document "Gates Grep.indd" of application "Adobe InDesign CS3"}

       

       

      I would like to get the separated numbers and put them in to a list

       

      eg. {"1","23", "4","56","7,"12"}

       

       

      Thanks for any help on this

       

      LJ

        • 1. Re: Process Indesign Grep Search
          [Jongware] Most Valuable Participant

          I know absolutely nothing of AS, but it might be worth pointing out that GREP (and regular findText as well) does not return regular text, but rather an array of pointers to InDesign formatted text. In JavaScript, you have access to the plain ASCII string using text.contents -- AS might be able to do the same.

           

          .. the separated numbers ..

           

          Your example list does not contain numbers but strings, which will lead to problems if you try to compare them ("2" being larger than "10"). Don't forget to convert them to numbers before comparing.