Hey, that was far more hard than I thought!
This script appears to be working -- but, admittedly, I only tested it with a 20-page document and some random reiterations. Run on a copy of your document, and holler if it ain't right. (And, boyo, do I hope it works ...)
You can fill in your new order in the first line, comma separated. You can also enter a range, like "5-10", if you happen to have a few pages in the original order. All numbers should be entered inbetween the quotes on one single line.
var order="1,20,2,19,3,18,4,17,5,16,6,15,7,14,8,13,9,12,10,11";
// Create an array out of the list:
ranges = toSeparate (order);
if (ranges.length != app.activeDocument.pages.length)
{
alert ("Page number mismatch -- "+ranges.length+" given, "+app.activeDocument.pages.length+" in document");
exit(0);
}
// Consistency check:
sorted = ranges.slice().sort(numericSort);
for (a=0; a<sorted.length-1; a++)
{
if (sorted < sorted[a+1]-1 ||
sorted == sorted[a+1])
alert ("Mismatch from "+sorted+" to "+sorted[a+1]);
}
// alert ("New order for "+order+"\nis "+ranges.join(", "));
// Convert from 1..x to 0..x-1:
for (moveThis=0; moveThis<ranges.length; moveThis++)
ranges[moveThis]--;
for (moveThis=0; moveThis<ranges.length; moveThis++)
{
if (moveThis != ranges[moveThis])
{
try{
app.activeDocument.pages[ranges[moveThis]].move (LocationOptions.BEFORE, app.activeDocument.pages[moveThis]);
} catch(_) { alert ("problem with page "+moveThis+"/index "+ranges[moveThis]); }
}
for (updateRest=moveThis+1; updateRest<ranges.length; updateRest++)
if (ranges[updateRest] < ranges[moveThis])
ranges[updateRest]++;
}
function toSeparate (list)
{
s = list.split(",");
for (l=0; l<s.length; l++)
{
try {
if (s.indexOf("-") > -1)
{
indexes = s.split("-");
from = Number(indexes[0]);
to = Number(indexes[indexes.length-1]);
if (from >= to)
{
alert ("Cannot create a range from "+from+" to "+to+"!");
exit(0);
}
s = from;
while (from < to)
s.splice (++l,0,++from);
}} catch(_){}
}
// s.sort (numericSort);
return s;
}
function numericSort(a,b)
{
return Number(a) - Number(b);
}
Copy and paste into a plain text editor -- the ESTK Editor that comes with InDesign is okay -- and save as "rearrangePages.jsx" into your scripting folder. It should immediately become available in your Scripts panel. Then just double-click to run.
It should warn you of duplicate numbers and some other mismatches I could think of. If it shows an error ("cannot create range"), your input is wrong. If it alerts you while running ("problem with page ...") it cannot move that page for some reason...
Absolutely No Guarantees. Run On A Copy Only. It May Seriously Damage Your Document If It Goes Wrong.