Skip navigation
Currently Being Moderated

applescript - grep

Jun 11, 2012 12:41 PM

I'm looking for examples of using grep with InDesign CS5.5.

 

I have a document that may or may not have one or more lines that contains an asterisk and a one or two digit number followed by a space.

 

I want to capture the two numbers, change the line from the asterisk to the end of the line to the point size of the numbers, then remove the asterisk and the two numbers and the space.

 

 

example:

 

100 Anystreet, *8 Suite 105

 

should become

 

100 Anystreet, Suite 105

 

I'm not sure if this is possible.  Any input??

 
Replies
  • Currently Being Moderated
    Jun 11, 2012 1:00 PM   in reply to ax1e2l_b3r4a5s6s

    Sure it's possible, just not with GREP alone, as it can't replace text with a point size that's in text. I suppose that's why you suggested AppleScript.

     

    How many different sizes do you need? If this is a limited number, you could do it with GREP styles -- one per font size, plus an additional one to hide the combo *(size) from view. A definite plus would be that changing the number immediately will change the text size. Downside would be you need a blindingly fast computer as soon as you cross over some magical threshold of number of GREP styles. I used to think they only got calculated once and then cached, somewhere in each paragraph bowels, but I found out the *very* hard way that's not the case. It seems all of them get re-calculated for your entire document on an event trigger as little as a mouse click ...

     

    I don't know AppleScript, but in Javascript it could be done as simple as:

     

    1. search for asterisk, wildcard digits, a space, and then anything else up to the end of a line.

    2. apply font size in that digit to the found string.

    3. delete asterisk plus digits plus space.

    4. repeat until satisfied.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 14, 2012 4:58 AM   in reply to ax1e2l_b3r4a5s6s

    The below code may will help you....

     

    app.findGrepPreferences.findWhat = "\\*[0-9]+[ ]"

    app.changeGrepPreferences.changeTo = "";

    app.activeDocument.changeGrep();

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 16, 2012 1:56 AM   in reply to ax1e2l_b3r4a5s6s

    Here below is sample code of FindChangeByList.applescript which I think help you to understand.

     

    on myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions)

              tell application "Adobe InDesign CS6"

                        --Clear the find grep/change grep preferences before each find/change operation.

                        set find grep preferences to nothing

                        set change grep preferences to nothing

                        set myScript to "tell application \"Adobe InDesign CS6\"" & return & "set properties of find grep preferences to " & myFindPreferences & return

                        set myScript to myScript & "set properties of change grep preferences to " & myChangePreferences & return

                        set myScript to myScript & "set properties of find change grep options to " & myFindChangeOptions & return

                        set myScript to myScript & "end tell" & return

                        do script myScript language applescript language

                        tell myObject

                                  set myFoundItems to change grep

                        end tell

                        --Clear the find grep/change grep preferences after each find/change operation.

                        set find text preferences to nothing

                        set change text preferences to nothing

              end tell

    end myFindGrep

     

    Shonky

     
    |
    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