8 Replies Latest reply on Sep 28, 2010 12:43 PM by kermy812

    AS CS3 Tell odd pages only

    kermy812

      Fairly new to applescript. I got a script where I'm putting text boxes and other stuff on every page, but now I need to only do it to odd pages. I'm was using this when I was doing every page:

       

      tell pages 1 thru 130

       

      Thought it would be something like this for odd pages only, but it wouldn't compile:

       

      tell pages 1 thru 130 by 2

        • 1. Re: AS CS3 Tell odd pages only
          Muppet Mark-QAl63s Level 4

          The term by is an increment for a loop… You could use it in a loop like so…

           

          tell application "Adobe InDesign CS2"

          tell active document

          set PageCount to count of pages

          repeat with i from 1 to PageCount by 2

          tell page i

          -- do stuff here

          display dialog "Page " & i giving up after 2

          end tell

          end repeat

          end tell

          end tell

          • 2. Re: AS CS3 Tell odd pages only
            Kasyan Servetsky Level 5

            Muppet Mark, what if page numbering starts from page 2 in the document? Your script would add text frames to even pages.

            I suggest another approach:

             

            tell application "Adobe InDesign CS3"
                 set doc to active document
                 set AllPages to pages of doc
                 tell doc
                      repeat with n from 1 to (count pages)
                           set thePage to item n of AllPages
                           set PageName to name of thePage as integer
                           if PageName mod 2 ≠ 0 then
                                tell thePage to make new text frame
                           end if
                      end repeat
                 end tell
            end tell

             

            Kasyan

            • 3. Re: AS CS3 Tell odd pages only
              Muppet Mark-QAl63s Level 4

              Kasyan, I would use mod as you have suggested to determine odd or eveness of integers. I almost posted more or less the same as what you have done in your example as an option. There is another thing to consider though… What if the name of the page contains characters that can not be simply coerced to integer…? Any sort of prefix or option other that digits will fail…

              • 4. Re: AS CS3 Tell odd pages only
                sstanleyau Level 4
                what if page numbering starts from page 2 in the document?

                If what you want is to do something only to right-hand pages, it would probably be better to use something like this:

                 

                tell application "Adobe InDesign CS4"

                tell document 1

                set thePageNums to document offset of every page whose side is right hand

                repeat with onePageNum in thePageNums

                tell page onePageNum

                -- do your stuff

                end tell

                end repeat

                end tell

                end tell

                Or even:

                tell application "Adobe InDesign CS4"

                tell document 1

                set thePageNums to document offset of the last page of every spread

                repeat with onePageNum in thePageNums

                tell page onePageNum

                -- do your stuff

                end tell

                end repeat

                end tell

                end tell

                • 5. Re: AS CS3 Tell odd pages only
                  Kasyan Servetsky Level 5

                  Marc, we never use section prefixes -- just plain Arabic numerals -- so I didn't think about this possibility. Anyway, I have to see a real InDesign document to make sure that the script works.

                   

                  Shane, your code is much more elegant -- I can always learn something new on this forum. Thanks.

                   

                  Kasyan

                  • 6. Re: AS CS3 Tell odd pages only
                    kermy812 Level 1

                    Thanks Kasyan! I used your code and it worked perfect. Although I don't understand what "mod" is. Can you explain what this is doing?:

                     

                         if PageName mod 2 ≠ 0 then

                     

                    I looked at a few websites on what mod is, but I'm just not getting it.

                    • 7. Re: AS CS3 Tell odd pages only
                      Muppet Mark-QAl63s Level 4

                      mod returns you the remaining value after the dividing by the parameter. So if you mod by 2 even integer numbers will result in zero left over and odd integer numbers will result in 1.

                      • 8. Re: AS CS3 Tell odd pages only
                        kermy812 Level 1

                        I think I get it.

                         

                        So If I end up doing even pages then:

                              if PageName mod 2 ≠ 1 then

                                     - or -

                              if PageName mod 2 = 0 then

                         

                        If I wanted to every 3rd page, I guess it would be something like:

                              if PageName mod 3 = 0 then