[AS] Iterate over page names throws exception
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