I have a problem with InDesign CS6. I have a Document with a few pages. Now I’d like to order these Pages in the correct numeric Sort with AS.
Here is what I’ve got:
tell application "Adobe InDesign CS6"
set pageCount to count pages of active document
repeat with i from 2 to pageCount
tell active document
set pN to name of page 2 as number
if pN is 2 then
set pN2 to pN
else
set pN2 to pN - 1
end if
set pN2 to pN2 as string
set theMovePage to (every page where name is pN)
set theForePage to (every page where name is pN2)
move theMovePage to before theForePage
end tell
end repeat
end tell
tell application "Adobe InDesign CS5.5"
tell active document
--sort the list
set sortedPageNameList to my sort(name of every page)
--move them to after last page beginning with list item 1 thru -1
repeat with i from 1 to count of sortedPageNameList
--to move by name -> after by offset
move page (item i of sortedPageNameList) to after page (count pages)
end repeat
end tell
end tell
on sort(stringList)
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {ASCII character 10}
set myString to (stringList as string)
set myNewString to do shell script "echo " & quoted form of myString & " | sort -n"
set myNewlist to (paragraphs of myNewString)
set AppleScript's text item delimiters to TID
return myNewlist
end sort
Hi, Marth and Hans. I started working on this before I saw a reply, so I may as well add in my solution as an option. This is a vanilla method that expands and contracts the document.
set pageMax to 2
tell application "InDesign CS"'s document 1
--quantize
repeat with counter from 1 to count pages
tell page counter's name as number to if pageMax < it then set pageMax to it
end repeat
--increase
repeat (pageMax - (count pages)) times
make section with properties {page start:make page, name:"killMe", continue numbering:1}
end repeat
--arrange
repeat with counter from 1 to count pages
try
move page (counter as string) to page counter
end try
end repeat
--reduce
delete (pages whose name contains "killMe")
end tell