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:- Choose File -> New Group
- Name the new group Random
- 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.
- Make a new snippet in a group other than the Random group
- Set the Content: of the new snippet to AppleScript
- 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
- Set an abbreviation for this new snippet, for example: rrand
- 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
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!
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.)