Smileworthy

The Smile Blog, With News, Tips, Photos and Other Stuff That Makes Us Smile

Random TextExpander Snippets Made Easy

Posted 12/03/2011 by Greg

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: http://nerdgap.com/how-to-randomly-selected-snippets-in-textexpander/ 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.)

Comments

Thank you so much for your help with this. This is such a great feature, double-thanks to the Smile developers for implementing this!

I LOVE TextExpander and recommend it to anyone who will listen. If you write more than a few emails a day, it’s CRAZY not to use TextExpander!

Posted by Sheree Peña  on  12/05/2011  at  05:02 PM

Extremely cool feature! ... (Suggestion for those implementing it: Don’t change the name of the group as the AppleScript is looking for that specific name. Changing it would require some tweaking of the AppleScript.)

Posted by Todd Doubleu  on  12/09/2011  at  06:51 AM

Add Your Own Comment:

Remember my personal information

Notify me of follow-up comments?

Submit the word you see below: