Skip to main content
Steve Straus
Known Participant
April 15, 2022
Question

ID script to increase numbers?

  • April 15, 2022
  • 3 replies
  • 1941 views

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?

This topic has been closed for replies.

3 replies

Inspiring
July 15, 2024
jctremblay
Community Expert
Community Expert
April 15, 2022

@Steve Straus I have send you a personal script for that in your private message... 

 

brian_p_dts
Community Expert
Community Expert
April 15, 2022

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

 

Steve Straus
Known Participant
April 15, 2022

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. 

Community Expert
April 15, 2022

Perhaps copying just the text you need to a new doc - run the script - and copy it back.