5 Replies Latest reply on Jun 5, 2012 1:55 PM by ax1e2l_b3r4a5s6s

    applescript - replace text in specific text frame

    ax1e2l_b3r4a5s6s Level 1

      Throwing another one out there to is excellent forum:

       

      I know how to change text in a document:

       

      tell application "Adobe InDesign CS5.5"

                set find text preferences to nothing

                set change text preferences to nothing

       

        --Search the document for the string.

                set find what of find text preferences to "SigBelowT"

       

        --Replace the search with what we pulled from the db

                set change to of change text preferences to theSigCopyB

       

        -- this is the actual search and replace command

                set myFoundItems to change text

      end tell

       

      I'm trying to change text only in a specific paragraph, named as a layer in my source inDesign Document:

       

      tell application "Adobe InDesign CS5.5"

                tell the active document

                          try

                                    set find text preferences to nothing

                                    set change text preferences to nothing

                                    set Text_Frame to the text frame "PH"

                                    set find what of find text preferences to "~" of text frame Text_Frame

                                    set change to of change text preferences to " "

                                    set myFoundItems to change text

                          end try

                end tell

      end tell

       

      I've tried several iterations similiar to this one, but I'm not hitting the right combination.

       

      Suggestions??



        • 1. Re: applescript - replace text in specific text frame
          Loic.Aigon Adobe Community Professional

          Hi,

           

          I don't have exact syntax at hand but paragraphs have a findGrep method. So I guess you should write something like

          tell myparagraph

              set result to find grep

          end tell

           

          again, teh synatx is up to you but you get the idea. Besides what do you mean by "named as a layer in my source inDesign Document"?

          Loic

          • 2. Re: applescript - replace text in specific text frame
            ax1e2l_b3r4a5s6s Level 1

            Hi -

             

            It's named as an element under on a layer of the document.

             

            I use that name to find elements to change fonts, etc.  Just can't find the way to limit the search and replace to that text frame using that name.

            • 3. Re: applescript - replace text in specific text frame
              ax1e2l_b3r4a5s6s Level 1

              headed down this path:

               

              tell application "Adobe InDesign CS5.5"

                        try

                                  set myDoc to active document

                                  set Text_Frame to the text frame "PH"

                                  set find text preferences to nothing

                                  set change text preferences to nothing

               

                                  set find what of find text preferences to "~"

                                  set change to of change text preferences to " "

                                  tell myDoc

                                            tell Text_Frame

                                                      set myFoundItems to change text

                                            end tell

                                  end tell

                        end try

              end tell


              still not working

              • 4. Re: applescript - replace text in specific text frame
                Loic.Aigon Adobe Community Professional

                Hi,

                 

                Ok, you may need to tweak this snippet a bit. Right now, it will only apply changes to so names "foo" text frames.

                 

                tell application "Adobe InDesign CS5.5"
                          set find text preferences to nothing
                          set change text preferences to nothing
                          set find what of find text preferences to "~"
                          set change to of change text preferences to " "
                          tell active document
                  
                                    set tfs to all page items
                                    repeat with i from 1 to count of tfs
                                              set tf to item i of tfs
                                              if name of tf = "foo" then
                  change text of tf
                                              end if
                                    end repeat
                  
                          end tell
                end tell
                

                 

                Loic Aigon

                http://www.loicaigon.com