Shuffle pages Indesign

Does anyone know if it is possible to make a script to shuffle pages?

Hi,

I wrote this JavaScript a few month before for ID CS4 …

Hope it’ll work …

if (app.documents.length < 1){ 
alert("Bitte zuerst ein Dokument öffnen."); 
exit(); 
    } 
 
 
var thePages = app.activeDocument.pages; 
 
main() 
 
function main(){ 
var randomList = createRandomList(thePages.length);     
    movePages(randomList); 
        } 
 
function createRandomList(n){ 
    var tmpList = []; 
while (n > 0){ 
    var n = n - 1; 
    tmpList.push(n); 
        }     
return tmpList.sort(shuffle); 
    } 
 
function shuffle(){ 
    var x = Math.random(); 
     
   if (x >= 0 && x <= 0.33)  
   { 
return 0; 
} 
else if (x > 0.33 && x <= 0.66) 
{ 
return 1; 
  } 
  else 
  { 
      return -1; 
       } 
 
} 
 
function movePages(nbrList){ 
    for (var p = nbrList.length - 1; p >= 0; p--){ 
             thePages[nbrList[p]].move(LocationOptions.AT_BEGINNING)   //eigentlich egal, die options ... 
                } 
        } 

Guten Tag,

thanks for helping me out!

I found this script on the internet:


aDoc = app.activeDocument;
for (i=0;i<aDoc.pages.length;i++){
	aSide = aDoc.pages[i].side;
	aSide = aSide + "";
	aDoc.pages[i].insertLabel("direction",aSide);
	}
aDoc.documentPreferences.allowPageShuffle = true;
aDoc.documentPreferences.facingPages = false;
aDoc.documentPreferences.allowPageShuffle = false;
aDoc.documentPreferences.facingPages = true;
for (i=0;i<aDoc.pages.length;i++){
	myPage = aDoc.pages[i];
	mySide = myPage.extractLabel("direction");
	if (mySide == "1818653800"){
		myPage.move(LocationOptions.atEnd,myPage,BindingOptions.leftAlign);
		}else{
		myPage.move(LocationOptions.atEnd,myPage,BindingOptions.rightAlign);
		}
	}

it works really fine for what I needed. I only need a reversible script of this script. I just know a bit of applescript, but no nothing about javascript, so I can’t make the reversible script.
Do you want to help me with the reversible script?

Hm,

this is no shuffle script as it turns left pages to right pages and reverse…

it offers two options for the use:


aDoc.documentPreferences.allowPageShuffle = true / false;
aDoc.documentPreferences.facingPages = true / false;

so, for example: if you use it like this … a second run of the script will reverse the order.
Back on start :wink:

aDoc = app.activeDocument;
for (i=0;i<aDoc.pages.length;i++){
	aSide = aDoc.pages[i].side;
	aSide = aSide + "";
	aDoc.pages[i].insertLabel("direction",aSide);
	}
aDoc.documentPreferences.allowPageShuffle = true;
aDoc.documentPreferences.facingPages = true;
for (i=0;i<aDoc.pages.length;i++){
	myPage = aDoc.pages[i];
	mySide = myPage.extractLabel("direction");
	if (mySide == "1818653800"){
		myPage.move(LocationOptions.atEnd,myPage,BindingOptions.leftAlign);
		}else{
		myPage.move(LocationOptions.atEnd,myPage,BindingOptions.rightAlign);
		}
	}

I guess I don’t get you right … and JavaScript is OffTopic here …

You’ll find one of the best Indesign-Scripting-Forums at www.hilfdirselbst.ch

Feel Yourself invited :slight_smile: