2 Replies Latest reply on Aug 20, 2014 12:50 PM by nellbern

    grep prices & pattern  applescript

    nellbern

      Hello, I'm not able to compile the script below. (Syntax eror Expected "" but found unknown token). It is not a complicated search but can't get it to work.  Would love an explanation if possible where my error resides. I also tried the FindChangebyList applescript but I'm having unknown token  error  too

       

       

      Need to perform 2 GREP finds.

      Example 1 :

      $1.99 5.99 $189.99 599.99. I know in Indesign the $ symbol is problematic so in the Find/change/Grep i'm using the unicode value. This GREP search works perfect but not in the script.  \x{0024}?[\d.]+\d{2}. I found that I needed to add an xtra \ to the digits  but still i'm not able to compiling it  \x{0024}?[\\d.]+\\d{2}

       

      Example 2:

      Find a pattern & replace with a tab

       

      Tab (might be there or not)

      Find literal 120

      followed by 2 uppercase letters

      followed 5 digits

      after the 5 digits (uppercase |or digits) might be there or not  

       

      example codes: 120AB12345, 120BC78945CD788, 120BC15935ABCL

       

      tell application "Adobe InDesign CS4"

        set find text preferences to nothing

        set change text preferences to nothing

       

      --Set FindWhat

        set find what of find grep preferences to "\x{0024}?[\\d.]+\\d{2}"

        --Find $1.99, $11.99, $119.99, 1599.99 The $ symbol (unicode \x{0024}) might be there or not

      set change to of change grep preferences to "" --replace with nothing

       

        set find what of find grep preferences to "\t?120[\u]{2}[\d]{5}([\u|\d]+)?"

        set change to of change grep preferences to "\t" --replace with a tab

       

      --set the  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

       

      change grep

       

        set find grep preferences to nothing

        set change grep preferences to nothing

       

      end tell

        • 1. Re: grep prices & pattern  applescript
          Kai Rübsamen Adobe Community Professional

          Hi,

           

          first of all, I have no idea how to write an applescript . So this is my first one.

           

          Some thoughts:

          1. If you escape something, you must escape it in general, so not only digits, but also \x{0024} or \t  >> \\x and \\t

          2. If you have two queries, you must set 'change grep' twice

          3. Some cosmetics: \x{0024} can be written as \x24 and [\d]{5} should be written als \d{5}.

           

          With some changes, this lines work for me:

          tell application "Adobe InDesign CC 2014"
              
              set find grep preferences to nothing
              set change grep preferences to nothing
              
              
              set find what of find grep preferences to "\\x24?\\d+\\.\\d{2}"
              set change to of change grep preferences to "" --replace with nothing    
              change grep
              
              
              set find what of find grep preferences to "\\t?120\\u{2}\\d{5}([\\u|\\d]+)?"
              set change to of change grep preferences to "\\t" --replace with a tab        
              change grep
              
              set find grep preferences to nothing
              set change grep preferences to nothing
              
          end tell
          

           

          – Kai

          • 2. Re: grep prices & pattern  applescript
            nellbern Level 1

            Thanks Kai. I'm trying a different approach. I'm using POSIX classes for finding $ & the prices. When I'm using the Find & Change windowThe code is compiling but it's not finding anything. Do i need escape characters too. If that's the case where I should put the escape character \\

             

            tell application "Adobe InDesign CS4"

              set find text preferences to nothing

              set change text preferences to nothing

             

            --Set FindWhat

              set find what of find grep preferences to "~h?[[=$=]]?[[:digit:]][[:digit:]][[=.=]][[:digit:]][[:digit:]]"

              --Find $11.99, The $ symbol might be there or not

            set change to of change grep preferences to "" --replace with nothing

             

              set find what of find grep preferences to "\\t?120[\\u]{2}[\\d]{5}([\\u|\\d]+)?"

              set change to of change grep preferences to "\t" --replace with a tab

             

            --set the  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

             

            change grep

             

              set find grep preferences to nothing

              set change grep preferences to nothing

             

            end tell