3 Replies Latest reply on Apr 17, 2010 6:24 PM by Stephen Horne

    affecting threaded text frames in applescript

    Stephen Horne

      I'm creating a script that sets the character style of the first character of a paragraph, only if the last word of the paragraph is contained by a list. I've got the script working perfectly, except that it does not make any changes to text in the second frame in a thread. Does anyone know what might be happening?

       

      tell application "Adobe InDesign CS3"

           tell active spread of active window

                repeat with oneFrame in (get text frames whose name of applied object style is "Object Style 1")

      --I'm wondering if this next tell is where I'm going wrong

                     tell parent story of oneFrame

      --should I be telling the frame itself? If so, how?

                          repeat with i from 1 to (count paragraphs of oneFrame)

                               if applied font of character 1 of paragraph i is "Rfnumbers Regular" then

                                    set routeBoxNumber to character 1 of paragraph i

                                    if exists word -1 of paragraph i then

                                          if greenList contains word -1 of paragraph i then

                                               set applied character style of character 1 of paragraph i to "Character Style 1"

                                               set topoNumberStyle to "Character Style 1"

                                               set topoNumbersList to topoNumbersList & character 1 of paragraph i

                                               set topoNumbersList to topoNumbersList & "Character Style 1"

                                          end if

                                     end if

                                end if

                           end repeat

                      end tell

                 end repeat

            end tell

      end tell

       

      thanks

        • 1. Re: affecting threaded text frames in applescript
          Stephen Horne Level 1

          After a bit of a closer look at the applescript replies when I run it, I've seen that when the text frames are threaded the script only affects the first frame in the story, effectively running the script twice on this frame. I'm still no closer to figuring out what to do about it though.

          • 2. Re: affecting threaded text frames in applescript
            [Jongware] Most Valuable Participant

              tell parent story of oneFrame

             

            Yeah that's right -- this one instruction always refers to the entire story from within any of its text containers.

             

            It might be an AS thing, but surely you don't have to change context (i.e., "tell" something else)?

             

            tell parent story of oneFrame -- <-- remove?

                   repeat with i from 1 to (count paragraphs of oneFrame)

             

            as "oneFrame" already seems to be the object you are targeting. You can refer directly to the paragraphs "of" a frame.

             

            (If you get it to work, you might want to check what happens with a frame whose first paragraph starts in the previous frame.)

            1 person found this helpful
            • 3. Re: affecting threaded text frames in applescript
              Stephen Horne Level 1

              Thanks Jongware,

               

              After reading your reply I've figured it out. I needed to keep the tell to the parent story in order to find the paragraphs whose name of applied font was what I am after, but then tell the individual paragraphs using another repeat:

               

              tell parent story of oneFrame

                   repeat with i from 1 to (count paragraphs of oneFrame)

                        try

                             if name of applied font of character 1 of paragraph i is "Rfnumbers Regular" then

               

                                  --this is what I was missing

                                  repeat with j from 1 to count paragraphs of oneFrame

               

                                       tell paragraph j of oneFrame

                                            set routeBoxNumber to character 1 of paragraph i

               

              Thanks for your help