Reply To: Sort a Book?

#85226
Ari Singer
Member

Peter, I’m afraid you left out the closing parentheses, as well as the immediate call to invoke it.

I fixed it for you:

(function () {
  var list = [];
  var docs = app.books[0].bookContents;
  for (var i = 0; i < docs.length; i++) {
    list.push ({name: docs[i].name, firstPage: Number(docs[i].documentPageRange.replace(/-\d+/,''))});
  }

  list.sort (function (a,b) {return a.firstPage - b.firstPage})

  for (i = list.length-1; i >= 0; i--) {
    docs.item(list[i].name).move (LocationOptions.AT_BEGINNING);
  }
})()

Ari

This article was last modified on May 25, 2016

Comments (0)

Loading comments...