5 Replies Latest reply on Aug 24, 2012 7:03 AM by Randolph McMann

    Formatting the next paragraph

    Randolph McMann

      I am thankful that Adobe has made InDesign so thoroughly scriptable. Nothing is better than the speed and accuracy you get with a good scripting solution! And I’m grateful for the great discussion forum; usually I can find an answer to any issue here. Unfortunately I haven’t found an answer to this problem (I’m probably not looking in the right places.) Hopefully someone out there can help me.

       

      I am working on an InDesign CS3 document and using AppleScript. I need to apply a paragraph style to 366 paragraphs. The document is structured this way:

       

      Date paragraph (which has an already applied paragraph style called “Date”)

      Title paragraph (to which I would like to apply a paragraph style called “Title”)

      Body paragraphs

       

      How can I use AppleScript to apply the paragraph style “Title” to those Title paragraphs? The only commonality they have is that, in every instance, they immediately follow a Date paragraph.

       

      Thanks in advance!

        • 1. Re: Formatting the next paragraph
          -hans- Level 4

          hi,

          just for the "whose" ;-)

           

          won't work with styles in groups ...

           

          set toSearch to "Date"
          set toSet to "Title"
          
          tell application "Adobe InDesign CS3"
              tell active document
                  set myStories to every story
                  repeat with i from 1 to count of myStories
                      set myStory to item i of myStories
                      try
                          set applied paragraph style of (first paragraph of myStory whose (index is greater than (index of first paragraph of myStory whose (name of applied paragraph style is toSearch)))) to toSet
                      end try
                  end repeat
              end tell
          end tell
          
          • 2. Re: Formatting the next paragraph
            TᴀW Adobe Community Professional & MVP

            If you want a general-purpose, flexible script that does this, check out

            "Change consecutive paragraphs", under the Scripting tab on my website:

            www.freelancebookdesign.com. There's a free demo to download.

             

            Ariel

            • 3. Re: Formatting the next paragraph
              Randolph McMann Level 1

              Thank you, Hans. Right now it seems to only work on the first paragraph. I need to work on the repeat structure. Any ideas?

              • 4. Re: Formatting the next paragraph
                -hans- Level 4

                Hi,

                 

                sorry didn't read your post as carefully as I should have ...

                set toSearch to "Date"

                set toSet to "Title"

                 

                tell application "Adobe InDesign CS3"

                    tell active document

                        set myStories to every story

                        repeat with i from 1 to count of myStories

                            set myStory to item i of myStories

                            tell myStory

                                --get indexes of pStyles whose applied Paragraph Style is toSearch

                                set dateParaList to (index of every paragraph whose (name of applied paragraph style is toSearch))

                                repeat with p from (count of dateParaList) to 1 by -1

                                    set myIndex to (item p of dateParaList)

                                    try

                                        set applied paragraph style of (first paragraph whose (index is greater than myIndex)) to toSet

                                    end try

                                end repeat

                            end tell

                        end repeat

                    end tell

                end tell

                 

                 

                Hope it'll work

                 

                Another approach could be to use find-change-scripting.

                • 5. Re: Formatting the next paragraph
                  Randolph McMann Level 1

                  The new script you suggested does the trick nicely, Hans.

                   

                  Thank you so much! You, sir, are a genius, and you've saved me tons of time and made the document more accurate to boot.