Random Responses

How to Send Random Responses with TextExpander

Do you ever find that you’re sending the exact same messages over and over? Maybe this bothers you and you want to mix things up, but you don’t have the time to come up with witty and creative responses to every message. TextExpander can help you automatically send random responses to spice things up.

Recently, we were talking to David Sparks about his session at our Virtual Summit, and he asked if it’s possible to create a TextExpander Snippet that pulls random responses every time you trigger it. Specifically, he wanted to create a Snippet to nicely tell people no, giving a different variation of the response each time.

Turns out, yes it is possible, and we’ll explain how to do it. But if you want to try out the Snippet yourself, install MacSparky’s Random No Snippets Public Group. There are many supporting Snippets in the group, but the key one is no.random. Once the Snippet Group is installed, typing no.random expands into one of six phrases:

  • “I am about to begin a work of great importance and therefore beg that in reference to calls and correspondence you will consider me dead for the next two months.”
  • “I am unable to do as you ask.”
  • “I can not, for secret reasons.”
  • “I greatly regret that I cannot do what you so kindly suggest.”
  • “I would prefer not to.”

And then finally, we have this lengthy polite decline from Mark Twain:

“I hope I shall not offend you; I shall certainly say nothing with the intention to offend you. I must explain myself, however, and I will do it as kindly as I can. What you ask me to do, I am asked to do as often as one-half dozen times a week. Three hundred requests a year! One’s impulse is to freely consent, but one’s time and necessary occupations will not permit it. There is no way but to decline in all cases, making no exceptions, and I wish to call your attention to a thing which has probably not occurred to you, and that is this: that no man takes pleasure in exercising his trade as a pastime. Writing is my trade, and I exercise it only when I am obliged to. You might make your request of a doctor, or a builder, or a sculptor, and there would be no impropriety in it, but if you asked either of those for a specimen of his trade, his handiwork, he would be justified in rising to a point of order. It would never be fair to ask a doctor for one of his corpses to remember him by.”

These might be a little silly, but having a Snippet that can produce semi-random replies can be helpful for many fields, like customer service and sales, where you have to send out the same messages over and over again but want to add a bit of variation so you and your team don’t sound like robots.

Let’s explain how we did it, and then we’ll show you how to customize it for your own purposes, even if you don’t know how to code.

JavaScript to the Rescue

To create a Snippet that expands into random responses, we turn to TextExpander’s often-overlooked JavaScript functionality, which lets you perform advanced operations like this. The no.random Snippet uses JavaScript to call another Snippet—entriesForRandom, which is a list of other Snippets that are possible choices for the randomizer.

The script counts the number of possible Snippets to expand, generates a random number, and expands the Snippet corresponding to that number.

try {
// Check if entriesForRandom snippet exists.
    // Get count of random entries
    const count = entriesForRandom.length;
    // Pick random index
    const randomIndex = Math.floor(Math.random() * count);
    // Return entry with randomly chosen index
}catch (err) {
    // Post helpful error if entriesForRandom does not exist
    "Please create a snippet with Content: JavaScript, " + 
    "abbreviation 'entriesForRandom', and snippet content of:\n" +
    "\tconst entriesForRandom = [\n"+
    "\t\t\"one\",\n" + 
    "\t\t\"two\",\n" + 
    "\t\t\"three\",\n" + 
    "\t\t\"four\",\n" + 

If you ever create your own Snippet group with this code, or any JavaScript code, be sure to set the Content Type to JavaScript so TextExpander understands that it’s working with code.

Make sure Content Type is set to JavaScript

As we mentioned, this Snippet calls the entriesForRandom Snippet to get a list of possible Snippets to expand into:

var entriesForRandom = [

Again, Content Type is set to JavaScript. This little bit of code creates an array of Snippets, a programming term for a list, and assigns that array to the variable entriesForRandom.

With a basic understanding of how the Snippet works, let’s walk through how you can make a copy of the Snippet Group and customize it to generate your own random responses.

Customize “Random No” for Your Own Random Responses

First, you must install the MacSparky’s Random No Snippets Public Group. Once it’s loaded in TextExpander, find it in the sidebar, right-click it (or Command-click on a Mac), and choose Duplicate from the menu. This creates an exact copy in your Personal library.

Duplicating the MacSparky random responses group

Next, find “MacSparky’s Random No Snippets copy” in the sidebar. Let’s rename it by right-clicking the Group name and choosing Group Settings. In the Name field, select all the text and replace it. For this example, we’re going to create a “Random Yes” Snippet Group.

Renaming the random responses group

Now go into the Snippet Group, select every Snippet other than no.random and entriesForRandom and delete it. Shift-click is handy here: click the first Snippet in the Group, and then Shift-click the no.prefer Snippet. Then press Backspace or Delete and click Delete Snippets.

Selecting the random responses Snippets to delete them

Next, let’s rename the David Sparks Random Nos Snippet and give it a new abbreviation. In this case, we named our Snippet Random Yes with an abbreviation of yes.random.

New label and abbreviation for our random responses group.

Then in the group, create the Snippets to feed into the randomizer. Here are the abbreviations and what they expand into:

  • yes.love: “I’d love to!”
  • yes.happy: “Happy to do so!”
  • yes.glad: “I’d be glad to!”

Now we need to modify the entriesForRandom Snippet to tailor it to our new Snippet Group.

  1. Change the Label and Abbreviation to something unique. In our example, we renamed it to entriesForYesRandom.
  2. Go into the Snippet content and change entriesForRandom to the new Snippet name.
  3. Change the entries in the array to represent the new Snippets. Each Snippet needs an entry in this format: “%snippet:SNIPPET_NAME%”
Highlighted changes to the entriesForRandom Snippet

One last step: edit the randomizer Snippet—yes.random in our example— to change every reference to entriesForRandom to our new random entries Snippet—entriesForYesRandom in our example.

Highlighted changes to the Random Yes Snippet

Now, you should be able to try out your new random Snippet and have it work immediately! If it doesn’t, these are the most common causes:

  1. Make sure you replaced all references to entriesForRandom and spelled the new Snippet correctly.
  2. Be sure you formatted the entriesForRandom Snippet—or whatever you replaced it with—correctly. See the screenshots for examples.

You can use this technique for all sorts of random responses: random greetings, sign-offs, sales pitches, or queries for information.

Here are some more top TextExpander tips:

Comments and Discussion

  1. Dear TextExpander Team,

    I’ve long been a fan of TextExpander, heralding it as one of my top productivity tools. From simple snippets to somewhat complex automations, it’s been a tool I’ve leaned on to make my daily computer tasks a breeze. That’s why it’s disappointing to see the disparity in feature sets when it comes to different operating systems, specifically Windows.

    As a Windows user, I’ve noticed the Mac version has AppleScript and Unix has ShellScript. Yet, on Windows, we’re left in the dust with basic and poorly documented JavaScript capabilities. No Promises, no async/await – it’s like being handed a Ferrari with a lawnmower’s engine.

    Including ‘fetch’ in the environment, without Promises, feels akin to teasing a child with candy – it’s there, but not really. Did someone mention a fetch quest? Because that’s what it feels like trying to utilize it to its fullest potential.

    Also, could we talk about the documentation? It’s a bit like handing me a treasure map without the ‘X.’ A lot of hints, but I’m still not quite sure what I’m digging for.

    I know developing software isn’t a walk in the park, but TextExpander isn’t exactly a newcomer in the industry. It’s disheartening to see a lack of parity across platforms for a tool that has so much potential.

    I hope my sentiments are taken constructively. We, the Windows user base, simply desire an experience that is as robust and full-featured as the one enjoyed by our Mac counterparts. We believe in TextExpander and its potential to revolutionize productivity for all, regardless of their OS preference.

    Cheers to hoping we Windows users are not eternally relegated to being the ‘TextExpander Lite’ crowd.

    Yours, in search of full-featured text expansion,

Comments are closed.