Skip to main content
Participant
October 16, 2012
Question

Can you sort indesign pages alphabetically?

  • October 16, 2012
  • 2 replies
  • 4681 views

I have a document with over 200 page and I want to sort the pages alpahetically after the heading on every page.The headings have one paragrah style. The document is singel pages, but there is two text frames on ever page. Many pages have also the same heading, so I hope to sort them in the  same order in which the document is now.

If you see the images under, I want to sort the pages alphabetically after the "heading" in bold to the right (txt:Best Buys Natural Wines)

Is it possible with a script or something else?

This topic has been closed for replies.

2 replies

Trevor:
Legend
October 16, 2012

Ok This is what you were after.

This assumes that you use a Paragraph style for your header AND THERE IS ONLY ONE HEADER ON EACH PAGE WHICH IS ONLY ONE PARAGRAPH LONG


// Script by Trevor to sort Pages according to alphabetical order of Page Headers

// http://forums.adobe.com/thread/1082984?tstart=0

var doc =  app.documents[0], myHeaders, l;

app.changeGrepPreferences = app.findGrepPreferences = null;

app.findGrepPreferences.appliedParagraphStyle = "My Header";

// Change above to the name of header style

myHeaders = doc.findGrep();

for (n=0; n < myHeaders.length-1; n++) $.writeln([myHeaders.contents]);

myHeaders.sort (function (a,b) {if (a.contents.toLowerCase() > b.contents.toLowerCase())  return 1 else return -1})

l = myHeaders.length;

while (l--) myHeaders.parentTextFrames[0].parentPage.move (LocationOptions.AT_BEGINNING);

Participant
April 3, 2016

thanks ..awsome script i've been searching for a while

but i need to add certain lines to this script hope you can help me

now i have these paragraph style (for certain chapters)

-Palm Trees ---paragraph style for chapter 1

-Trees ---paragraph style for chapter 2

-Shrubs---paragraph style for chapter 3

-Ground Covers---paragraph style for chapter 4

-Climbers---paragraph style for chapter 4

-Succulents---paragraph style for chapter 4

i want to arrange the pages that have these paragraph styles alphabetically in that exact order (arranging the paragraph)...can you help me in this?

be noted that each chapter has its own Master Page

Inspiring
April 6, 2016

yes it would help the thing that is iam new to indesign scripting ...and i was just trying my luck


The error message tells you what the error is - GroundCovers is not defined. It is declared but you are not assigning it any value.

Your basic code would be:

var doc =  app.documents[0], Palmtrees, Trees, Shrubs, GroundCovers, Climbers, Succulents, l;

app.changeGrepPreferences = app.findGrepPreferences = null;


app.findGrepPreferences.appliedParagraphStyle = "Plant Name (Succulents)";

Succulents = doc.findGrep();

for (n=0; n < Succulents.length-1; n++) $.writeln([Succulents.contents]);   

Succulents.sort (function (a,b) {if (a.contents.toLowerCase() > b.contents.toLowerCase())  return 1 else return -1})   

l = Succulents.length;  

while (l--) Succulents.parentTextFrames[0].parentPage.move (LocationOptions.AT_BEGINNING);


// then you repeat:


app.findGrepPreferences.appliedParagraphStyle = "Plant Name (Climbers)";

Climbers = doc.findGrep();

for (n=0; n < Climbers.length-1; n++) $.writeln([Climbers.contents]);   

Climbers.sort (function (a,b) {if (a.contents.toLowerCase() > b.contents.toLowerCase())  return 1 else return -1})   

l = Climbers.length;  

while (l--) Climbers.parentTextFrames[0].parentPage.move (LocationOptions.AT_BEGINNING);


etc... Basically you need to change what you are searching for BEFORE every search.


Let me know if this helps.


Michael

Trevor:
Legend
October 16, 2012

Do the pages contain linked stories?

If not you can script it easily with the move command