Free Script to Change All Numbers in a Document using Math
What if you had a document with 2,000 prices in it, all in US dollars, and you wanted to change them all to Euros? Taking a look at today’s exchange rate, we see that the dollar is around 1.3 Euros. It’s easy to do a find/change to replace the $ symbol with the ?. But what about all those numbers? Wouldn’t it be cool if we had a script that simply multiplied all the numbers in the document by 1.3? Too bad that’s impossible.
Scripting pro Steve Wareham just sent me a script that lets you multiply, divide, add, or subtract the numbers in your document. It’s called NumberAdjuster, and we’re releasing it free here, as promoware. (In other words, if you like it, go hire him to do some scripting the next time you need something automated.)
Here’s how it works: You download the script, unzip it, install it, then double-click it in the Scripts panel (Window > Automation > Scripts). [See note at end of this article for a different version of this script.] You should see a dialog box like this:
You can control whether the operation is performed on the entire document or just the current selection. You can specify which math operation to perform and what to use as the operator (such as “multiply by 1.3” or “add .99”). You can constrain the operation to numbers with a prefix (such as only numbers with a $ or £, or even only apply it to negative numbers by typing a dash). And you can constrain the operation to numbers with a particular character style.
The first time you run it, it might be slow, because it has to write a little preferences file to disk (so it remembers what you did next time you run the script). After that, it’s pretty dang fast.
Don’t type in two prefix characters (such as -$ for negative dollars). It can’t handle that, and the result will require an undo. In fact, as with running any script, I strongly suggest saving your document first, in case you need to choose file > revert. (You can undo the math operations, but it undoes them one number at a time, which isn’t much fun if you’ve just changed a thousand numbers.)
Note that this script won’t change the prefix for you (changing dollars to euros, or whatever). It only adjusts the number. But again, changing the symbol is as easy as Edit > Find/Change.
I was just chatting with Anne-Marie about this, and she told me she heard of a catalog company that put a “take 15% off all the prices on this page” sticker on every page of a big catalog because it was easier and faster than going ahead and changing the prices. No longer! This script is a marvel.
[Update: Here is an updated version of the script, written by Peter Kahrel.]