Copy link to clipboard
Copied
I am working on a new edition of a book that has grown by two pages in the middle of the book. I need to update the manually created index to reflect this repagination. I have a memory of a script that would search out page ranges and then could increase it by a set amount (in my case, anything from pages 204ā422 becomes 206ā424 [+2]). I have done an exhaustive search online and can't track down anything that would work.
Anyone know of a script that can do such a miracle?
Copy link to clipboard
Copied
Copy the index to a new document then try this?
var d = app.activeDocument;
var f = "\\d+(-\\d+)?$";
app.findGrepPreferences.findWhat = f;
var fs = d.findGrep();
var t, i, j, s;
for (var i = 0; i < fs.length; i++) {
t = fs[i].contents.split("-");
s = "";
for (j = 0; j < t.length; j++) {
if (j == 0) {
s += (Number(t[j]) + 2).toString();
} else {
s += "-" + (Number(t[j]) + 2).toString();
}
}
fs[i].contents = s;
}
Copy link to clipboard
Copied
Not being a script writer and only a GREP novice, I am trying to read this code to figure out what it does. It seems to find a number range and then adds +2 to the number. Since this is an index, not all numbers are ranges. My biggest "issue" is that not all numbers need to be increase, just those after the two new pages were added. Per the attached screen grab, you can see that this index uses a variety of numbering and not all numbers should change.
Copy link to clipboard
Copied
Perhaps copying just the text you need to a new doc - run the script - and copy it back.
Copy link to clipboard
Copied
I'll give it a shot. Thx
Copy link to clipboard
Copied
Edit: I had an error in the GREP; it now accommodates index entries that are not ranges, and those that are. Let us know how it went.
Copy link to clipboard
Copied
@Steve Straus I have send you a personal script for that in your private message...