3 Replies Latest reply on Dec 15, 2011 7:02 AM by rob day

    Applescript find/change problem

    LukeF11 Level 1

      I have some text which needs to be styled in InDesign CS4 which has a bunch of extraneous tags ( eg. <b>, <i>, etc.). I have customised the FindChangeList.txt file that supports the FindChangeByList.applescript file to do things like:

       

       

      {find what:"<i>"}{change to:"^S"}

       

       

      which can then be picked up by a nested style. All good so far.

       

      Problem: the applescript will just not 'see' the strings <b> or </b> in FindChangeList.txt. It treats them like they aren't there. I can do it using the find/replace within InDesign, it works fine there, but my problem is that I have hundreds of pieces of copy to import and I'd like to automate as much as possible. Using GREP has the same effect, ie. works in find/replace within InDesign, but not with applescript.

       

      Any help would be greatly appreciated as this is really killing me at the moment. Thanks!

       

      Content of FindChangeList.txt follows. The command in the final line works, the command in the second-last line doesn't.

      (FYI the second line of code contains 'InDesign CS3' regardless of whether I use CS3 or CS4. I guess they didn't update the file)

       

      --FindChangeList.txt

      --A support file for the InDesign CS3 AppleScript FindChangeByList.applescript

      --

      --This data file is tab-delimited, with carriage returns separating records.

      --

      --The format of each record in the file is:

      --findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description

      --

      --Where:

      --<tab> is a tab character

      --findType is "text", "grep", or "glyph" (this sets the type of find/change operation to use).

      --findProperties is a properties record (as text) of the find preferences.

      --changeProperties is a properties record (as text) of the change preferences.

      --findChangeOptions is a properties record (as text) of the find/change options.

      --description is a description of the find/change operation

      --

      --Very simple example:

      --text          {find what:"--"}          {change to:"^_"}          {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}          Find all double dashes and replace with an em dash.

      --

      --More complex example:

      --text          {find what:"^9^9.^9^9"}          {applied character style:"price"}          {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}          Find $10.00 to $99.99 and apply the character style "price".

      --

      --All InDesign search metacharacters are allowed in the "find what" and "change to" properties.

       

      text          {find what:"<b>"}          {change to:"^S"}          {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}          Find all bold and replace with non-breaking space.

      text {find what:"<i>"} {change to:"^S"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find all italics and replace with non-breaking space.

        • 1. Re: Applescript find/change problem
          rob day Adobe Community Professional & MVP

          You probably should post this in the ID Scripting forum. Here's an example of some simple AppleScript find and changes that might help:

           

           

           

          --find and replace keyboard formating

          tell application "Adobe InDesign CS5.5"

           

               --first clear the preferences

               set find text preferences to nothing

              set change text preferences to nothing

             

              --replaces non breaking space with space

              set find what of find text preferences to "^s"

              set change to of change text preferences to "<0020>"

              set myFoundItems to change text

             

              --replaces soft return with return

              set find what of find text preferences to "^n"

              set change to of change text preferences to "^p"

              set myFoundItems to change text

             

              --replaces return space with return

              set find what of find text preferences to "^p<0020>"

              set change to of change text preferences to "^p"

              set myFoundItems to change text

             

              --replaces 2 returns with return

              set find what of find text preferences to "^p^p"

              set change to of change text preferences to "^p"

              set myFoundItems to change text

             

              --replaces return, tab, return with return

              set find what of find text preferences to "^p^t^p"

              set change to of change text preferences to "^p"

              set myFoundItems to change text

             

              --replaces space, return with return

              set find what of find text preferences to "<0020>^p"

              set change to of change text preferences to "^p"

              set myFoundItems to change text

             

              --replaces space, space with space

              set find what of find text preferences to "<0020><0020>"

              set change to of change text preferences to "<0020>"

              set myFoundItems to change text

             

              --replaces 3 tabs with tab

              set find what of find text preferences to "^t^t^t"

              set change to of change text preferences to "^t"

              set myFoundItems to change text

             

              --replaces 2 tabs with tab

              set find what of find text preferences to "^t^t"

              set change to of change text preferences to "^t"

              set myFoundItems to change text

             

          end tell

          • 2. Re: Applescript find/change problem
            LukeF11 Level 1

            Thanks Rob, will move the post there now.

            • 3. Re: Applescript find/change problem
              rob day Adobe Community Professional & MVP

              I checked the script and the lines in the text file have to be written consistently—there always needs to be a tab separating text, find what and include. If you use a space or other character the script will break. So this works (the triangle invisible is a tab):

               

              correct.png

               

              But this doesn't because there's a space, not a tab, between change and include:

               

              wrong.png

               

               

               

              You need this:

               

              text     {find what:"<b>"}     {change to:"^S"}     {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}

               

              text     {find what:"<i>"}     {change to:"^S"}     {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}

               

               

              Not this:

               

              text          {find what:"<b>"}          {change to:"^S"}          {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}

               

              text {find what:"<i>"} {change to:"^S"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}