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);

madarmat
Participant
August 4, 2016

Hello,

I found this script and it helps me alot, but i would like, if it's posible, to ignore numbers or the first 4 characters.

My problem is that my paragraph contains "year + name", and i want the pages sorted just by name. Now it sorts everything chronologicaly not alphabeticaly.

Inspiring
August 4, 2016

Hi Mad

Not tested but replace

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

with

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

HTH

Trevor


I would replace like this:

myHeaders.sort (function (a,b) {if (a.contents.toLowerCase().replace(/^\d{4}/,"")  > .contents.toLowerCase()).replace(/^\d{4}/,"")
  return 1 else return -1});

//if the year is at the beginning of the paragraph but watch for trailing spaces

or

myHeaders.sort (function (a,b) {if (a.contents.toLowerCase().replace(/\d{4}/,"")  > .contents.toLowerCase()).replace(/\d{4}/,"")
  return 1 else return -1});

//if year is not at the beginning

Michael

Trevor:
Legend
October 16, 2012

Do the pages contain linked stories?

If not you can script it easily with the move command