InDesign CS6 - Change Order of Spread / Pages

Hi everybody,

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



I hope you understand what I want to do. (Sorry my english is terrible I know…)
Here is a Screenshot:
http://s7.postimage.org/gar8vtznv/Bildschirmfoto_2012_09_26_um_07_32_55.png

Thanks for your help

Cheers
Marth

hi,

does this …


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