Script Description
This InDesign script is meant to help you quickly update numbers in an InDesign document. It works by getting the operation you want to perform on numbers from a dialog box, and the searching for numbers that match either a default or custom regular expression. There are options to only find number that have a specific paragraph style applied or follow a specific prefix character.
Looking at the Script
The core part of this script is finding text that is actually a number. To do that it uses a regular expression: [-]*[0-9][0-9,.]*\b. With that expression the findWhat function is used to get all the matches.
//Find matching numbers var mySearchGrep = app.findGrepPreferences.findWhat = mySearchPrefix + myGrep; var myFoundArray = mySearchScope[i].findGrep();
Once matches to the regular expression have been found we can perform the operation on them. The result of the operation is stored in the variable “myResult”.
//Perform the selected operation on the found number
if (myOperation == "+"){var myResult = (parseFloat(myFoundNumber) + myOperator) + "";}
else if (myOperation == "-"){var myResult = (parseFloat(myFoundNumber) - myOperator) + "";}
else if (myOperation == "*"){var myResult = (parseFloat(myFoundNumber) * myOperator) + "";}
else if (myOperation == "/"){var myResult = (parseFloat(myFoundNumber) / myOperator) + "";}
The script does call a few other functions to make it more useful. It provides options to round off the result, add a prefix character to the result, and search on a custom regular expression.
Finally, there is an option for counries who use a comma for a decimal point and a decimal point for a comma, i.e. “1.234,56”. Selecting this options effects the what is found and returned via the find/change funcitons. The operator field still needs to be formatted as “1,234.56” however.

