Skip to main content
July 27, 2010
Answered

[AS] Iterate over page names throws exception

  • July 27, 2010
  • 1 reply
  • 1942 views

Cheers,

Something's wrong with my AS export script. Looping over pages and getting the name

of current page will return "1" for page[0] but the exception for the following pages:

Can't make name of item 2 of {«class page» id 179 [snip] of "test.indd" of application

"Adobe InDesign CS3"} into type string

Can you help the AS rookie?

(*
     Export all open documents to single PDF documents.
     v1.0 07/2010
     Rasmus Olsen
     
*)
-- choose a folder and cast to string
set myFolder to (choose folder) as string
-- set timeout to 10 minutes
with timeout of (10 * 60) seconds
     tell application "Adobe InDesign CS3"
          try
               -- get PDF export presets as strings
               set presets to name of PDF export presets
               -- get selected list item as string
               set selected to {choose from list presets} as string
               -- iterate over documents
               repeat with doc in documents
                    set docname to name of doc
                    -- remove extension via newname
                    set newname to text 1 thru -6 of docname
                    if (count of pages of doc) > 1 then
                         -- doc's got more than one page
                         set docpages to pages of doc
                         -- iterate over pages
                         repeat with aPage in docpages
                              -- need help with this:
                              -- get page name as string trows an exception with all pages except page 1
                              set pagename to name of aPage as string
                              display dialog pagename
                              tell doc
                                   -- export page with pagename suffix
                                   export format "Adobe PDF" to (myFolder & newname & "_" & pagename & ".pdf") using selected without showing options
                                   close saving no
                              end tell
                         end repeat
                    else
                         tell doc
                              -- export page
                              export format "Adobe PDF" to (myFolder & newname & ".pdf") using selected without showing options
                              close saving no
                         end tell
                    end if
               end repeat
               -- catch..
          on error e
               display dialog e
          end try
     end tell
end timeout

This topic has been closed for replies.
Correct answer sstanleyau

It may need some parens, as in:

                              set pagename to (name of aPage) as string

although the "as string" is redundant. But you can simplify your loop a bit, by using something like:
repeat with i from 1 to count of pages
set pagename to name of page i
...

1 reply

sstanleyauCorrect answer
Inspiring
July 27, 2010

It may need some parens, as in:

                              set pagename to (name of aPage) as string

although the "as string" is redundant. But you can simplify your loop a bit, by using something like:
repeat with i from 1 to count of pages
set pagename to name of page i
...

July 27, 2010

Hey Stanley,

The () did the trick - thanks!

Rasmus