I ran into a situation yesterday where I wanted to create over a thousand TextExpander snippets. I won’t go into detail about why, but I thought I’d share my solution. In my case, I was working with a huge CSV file where one field would be the abbreviation and another would be the expansion. The script I’m sharing below only works with CSV files containing two fields (abbreviation, expansion), but it can easily be extrapolated to work with much more complex sources of data.
To use the script, you just need a CSV file. You can edit this in any spreadsheet that can export a CSV version of your file (Numbers, Excel, etc.), or you can just edit the list in a text editor if you know how to properly quote CSV strings containing special characters.
The script generates plain text snippets only, and by default sets the group to “Expand after any character.” You can change some of the settings for the group and snippets by editing the XML file, but take a look at an actual TextExpander group export file for reference1.
If you’re in a spreadsheet application, delete any header rows and give yourself just two columns. Fill the first field in each row with the abbreviation you want to use, and the second with the expansion. Export the sheet as a CSV. Then run the script, passing the CSV file as the first argument and the desired name of the TextExpander group file as the second (must have a
.textexpander extension). The filename will be used as the group name, but that’s quite simple to edit after import.
After the script has run, just double-click the resulting
.textexpander file in Finder to import it into TextExpander as a new group. All of your snippets from the CSV file should be there.
To run the script, save the raw text from below as
textexpander_gen.rb somewhere in your path and make it executable (
chmod a+x /path/to/textexpander.rb). Create your CSV file and run the script:
textexpander_gen.rb input.csv output.textexpander
Set the parameters you want on a group in TextExpander, right click the group and choose “Save a copy.” Open the resulting file in a text editor to see how the options are expressed in the plist format.↩