Random TextExpander Snippets Made Easy

We regularly get requests for a way to choose a random snippet from among a set of snippets. To date, we’ve pointed folks to this technique:


Now that TextExpander itself is AppleScriptable (as of version 3.3), there’s an easier and more flexible way to do this:

  1. Choose File -> New Group
  2. Name the new group Random
  3. Add snippets that you’d like to be chosen at random into the Random group. You can drag existing snippets from other groups into Random, or you can create snippets expressly for use in Random.

    Tip: if you are creating new snippets for use only as random snippets, you can save time and work by not assigning abbreviations to these snippets.

  4. Make a new snippet in a group other than the Random group
  5. Set the Content: of the new snippet to AppleScript
  6. Enter this for the snippet:
    tell application "TextExpander"
    	set groupCount to count (snippets of group "Random")
    	set randomIndex to random number from 1 to groupCount
    	return plain text expansion of snippet randomIndex of group "Random"
    end tell
  7. Set an abbreviation for this new snippet, for example: rrand

Any time you type rrand, you’ll get a random selection from among the snippets in your Random group.

The advantages of this technique over the one linked above are:

  • You need not know the abbreviations for all of the snippets in advance
  • You can add to and remove from your Random group without changing anything

(Thanks to Sheree Peña of Black Pixel for the inspiration for this post.)