Hi Everyone! I have a snippet that includes costs per document and associated fees (see screenshot). I want to auto calculate the total cost based on simple formulas. Can TextExpander do this?
Hi Christian! Great question — yes, TextExpander can do this! Fill-in fields on their own can’t do math, but JavaScript snippets can, and fill-in fields work inside them. So you can ask for the number of documents once, and the snippet calculates the total and builds the itemized list for you.
I know this looks like a lot but it’s just because of the code block ![]()
Here’s a snippet based on your fee structure. Create a new snippet, set the Content Type dropdown to JavaScript, and paste this in:
var docs = Number("%filltext:name=Number of documents:default=1%");
var transcripts = Number("%filltext:name=Transcript copies (0 if none):default=0%");
var intl = "%fillpopup:name=International shipping:default=No:Yes%";
var notaryService = docs * 30;
var notaryFee = docs * 10;
var apostilleService = 30;
var sosFee = docs * 20;
var transcriptFee = transcripts * 15;
var intlFee = (intl === "Yes") ? 30 : 0;
var total = notaryService + notaryFee + apostilleService + sosFee + transcriptFee + intlFee;
var out = "Based on your request, the total fee is $" + total + ".\n\n";
out += "Your charges are as follows:\n";
out += "• Notary Service Fee: " + docs + " documents = $" + notaryService + "\n";
out += "• Notary Fee: " + docs + " × $10 = $" + notaryFee + "\n";
out += "• Apostille Service Fee: $30\n";
out += "• Secretary of State Apostille Fee: " + docs + " × $20 = $" + sosFee + "\n";
if (transcripts > 0) out += "• Official Transcript Fee: " + transcripts + " × $15 = $" + transcriptFee + "\n";
if (intl === "Yes") out += "• International Express Mail Fee: $30\n";
out;
When you expand it, a single popup asks for the document count, transcript copies, and a Yes/No for international shipping. The total and itemized charges are calculated automatically — and the transcript and shipping lines only appear when they apply, so you won’t need your optional sections for those anymore.
A few notes:
- Keep your Inquiry section as a separate, regular snippet — it doesn’t need any math, and regular snippets keep your bold formatting.
- JavaScript snippets output plain text, so the receipt won’t have bold styling. That’s the one trade-off.
- All the fees are defined at the top of the script, so if prices ever change, it’s a one-line edit.
Alternatively we also work with ai platforms like Claude and ChatGPT. You could then use AI to build the snippets you need for you. Check out our TextExpander MCP Server Getting Started Guide don’t let the MCP name fool you. It’s just a fancy way to say connect to AI ![]()
Hope this helps — let me know how it goes or if you’d like help tweaking it!
All the best,
- Nick
Just to flag that if you are more comfortable having this computation built in either Excel or Google Sheets, as a multi-line output in a single cell (you know, lots of CHAR(10)s) – opposed to using JS in the snippet – you may have experienced this gotcha. When copying that output cell and then pasting elsewhere, you get…
"Based on your request, the total fee is $180.
Your charges are as follows:
• Notary Service Fee: 2 documents = $60
• Notary Fee: 2 × $10 = $20
• Apostille Service Fee: $30
• Secretary of State Apostille Fee: 2 × $20 = $40
• Official Transcript Fee: 2 × $15 = $30
"
Attempting to use CLEAN in Google Sheets to mitigate those quote marks – wrapping the formula constructing the multi-line output – just strips out all of that structure/formatting.
HOWEVER… if you copy it to the clipboard and then expand this JavaScript Textexpander snippet…
let text = TextExpander.pasteboardText;
if (
text.startsWith('"') &&
text.endsWith('"') &&
text.includes('\n')
) {
text = text.slice(1, -1).replace(/""/g, '"');
}
TextExpander.appendOutput(text);
…those errant opening and closing quotes will be stripped away prior to expansion.
As I say, just a tip if you prefer to use spreadsheets to construct calculated output. Goes to show Textexpander can have many creative uses. ![]()
