If you use both Mac and Windows you may have wished you could use your Mac TextExpander snippet files on your Windows computers or virtual machines. TextExpander radically speeds up your work if you often need to use the same text blocks, and having the same texts with the same hotstrings available on Windows makes life a lot easier.

This post provides a free Perl converter script and instructions for converting your Mac TextExpander snippet files so that you can use them on a Windows machine with the free, open-source AutoHotKey program. In addition to this I will show you how to manage your snippet files for multiple machines in a free Dropbox account. Dropbox is a much better solution for synching your snippets than MobileMe and if you combine these two strategies you’ll never have to worry about synching your snippets again – both on multiple Macs and across Mac and Windows machines (including Windows virtual machines in Parallels or Fusion).

Version 1.2:

Cursor position: The 1.2 version now supports the caret/cursor position macro. This will work reliably provided your snippets don’t contain the clipboard pasting macro or date macros that use full month and weekday names or date numbers without leading zeros. All these things will throw the position count off (AHK doesn’t have a “put cursor here” macro).

Version 1.1:

The 1.1 version adds the following improvements:

Expand mode (immediately, at delimiter with keep/delete) is read from TextExpander and exported to the AHK script.

Abbreviation mode (case sensitive/ignore case) is read from TextExpander and exported to the AHK script. However, “Adapt snippet to case of abbreviation” does not work in AHK – at least, I haven’t been able to make it work.

The keep/abandon delimiter macros in individual snippets are now evaluated and work correctly in AHK.

Warning and disclaimer

This conversion script and the instructions are provided free of charge without any warranty or liability whatsoever. The converter only reads your TextExpander snippets, it doesn’t write to them. Even so, you are responsible for protecting yourself by making backups. You’re welcome to edit and reuse the script as you like but only with attribution to Khoji on Tech and not in commercial products.

If you’re a Perl expert, cut me some slack: This is my first Perl project, I’m basically using it as a learning exercise with the Llama book. As far as I can see it works fine, but I’m sure that you’ll be able to improve it in lots of places. ;-)

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Germany License.

Download the script and AutoHotKey

If you’re familiar with Perl scripts and just want to get started click the download links below and go. The script is heavily commented and should be self-explanatory. Just enter your input and output file names and paths in the brief configuration section at the beginning and you should be good to go.

AutoHotKey just has to be installed on Windows, you don’t need to configure anything to get started. After you’ve converted your snippets just double-click on the .ahk script file in Windows to load it and your snippets will immediately be available on Windows.

Download the Perl Script
Download AutoHotKey

Limitations and Caveats:

This solution isn’t perfect, but it still works very well for most purposes. Here are the main limitations:

One-way only: You can only convert from TextExpander to AutoHotKey, not the other way. TextExpander’s XML files are radically more complex than the simple .ahk scripts and converting back in the other direction would be a major project. I may get around to it eventually, but not soon.

Plain text only: The formatted and binary content of snippets is ignored, only the plain text versions of each snippet are converted.

Limited HTML entity conversion: At the moment only the most basic HTML entities like < and > and & are converted. Adding more should be trivial, however, just add them to the sub charReplace routine using the same patterns that you see there for the other conversions.

No nested snippets: Support for nested snippets is not possible in AHK. Nested snippet macros are replaced by $$$snippet_name$$$.

Cursor position: AHK doesn’t have a macro for setting the caret (text insertion cursor) position. The converter calculates the position of the macro in the TextExpander version and then backspaces to that position after pasting the text in Windows. This will not be accurate in snippets that paste text from the clipboard or snippets that use date macros that paste the full names of months and weekdays (there’s no way to know exactly how long the string will be then, it depends on the current date).

More Detailed Instructions

Click on the following link to display the basic instructions for using the script to convert your TextExpander snippets. Everything will be a lot easier if you first set up a Dropbox and install the Dropbox software on both our Mac and your Windows machine. See further below for the Dropbox instructions.

Using the Converter Script

  1. If you haven’t already done so, download AutoHotKey and install it in Windows. You don’t need to configure anything in AutoHotKey — once it’s installed you’re ready to go.
  2. Now download the perl script and unpack it on your Mac. You can put it anywhere but it’s practical to save the tx_conv.pl script file in the folder where you want to put your converted files. If you’re using the Dropbox solution (see below) you should keep your TextExpander files, the script and your converted AutoHotKey files all in your Dropbox folder. Then everything is much easier and you never need to copy anything between computers.
  3. Open the tx_conv.pl script file in your favorite text editor and enter the path and name of your TextExpander settings file in the configuration section at the top. The file is normally called Settings.textexpander and is normally located in /Users/USERNAME/Library/Application Support/TextExpander/. You must enter the full path to your Settings.textexpander file! Using the ~/ prefix for your home directory won’t work. Also, you must escape any spaces in the path with a backslash. For example, if your user name is tomtom then your input file config line would look like this: my $textexpander = “/Users/tomtom/Library/Application\ Support/TextExpander/Settings.textexpander”
  4. Open a Terminal window on the Mac, change to the directory containing the script and type the following command: chmod a+x ./tx_conv.pl — this will make the script executable on your system.
  5. Enter the following command in the terminal to run the script: ./tx_conv.pl
  6. Then copy the .ahk output file to your Windows machine and double-click on it to load it. If you want to load the script every time you start Windows just put a link to it in the Startup folder inside your Programs folder for All Users (Explorer All Users > Programs > Startup). That’s it!
  7. For further details on using AutoHotKey see the AHK help file. 

Setting up the Dropbox solution

Using Dropbox is the easiest way to synchronize your TextExpander snippets across multiple Mac and Windows machines. It’s much better and more efficient than using MobileMe, which is often slow and unreliable, particularly in Europe.

Before you start: Open your TextExpander preferences on all your Macs and turn MobileMe synching OFF. Then go into your MobileMe settings in the OS X preferences and make sure that TextExpander is turned OFF in the synch settings there as well.

Where to put the script: Once you’ve set up the Dropbox solution you can put the conversion script directly in your Dropbox together with your TextExpander folder. You can also keep your .ahk output files for AutoHotKey there and run them directly from your Dropbox — you will still have local copies even when you’re not connected to the Internet.

Setting up the Dropbox Solution

(These instructions are adapted from information provided by the support staff of SmileOnMyMac, the makers of TextExpander.)

On your primary Mac machine:

  1. Download and install Dropbox and set up a free DropBox account. You get 2GB with the free account, which way more than you need for synching your snippets.
  2. Close System Preferences
  3. In the Finder, go to your Dropbox folder and create a folder called “Library.”
  4. Drag the ~/Library/Application Support/TextExpander folder to your Dropbox/Library folder.  Your TextExpander settings and snippets are now stored and synched with your Dropbox.
  5. Open a terminal window and type the following command to create a symlink for TextExpander to your DropBox folder: “ln -s ~/Dropbox/Library/TextExpander ~/Library/Application\ Support/TextExpander”

This symlink will redirect TextExpander to your DropBox folder to grab the snippet information.  Note that you won’t get any sort of confirmation in the Terminal that this operation succeeded.  You can confirm it by going to ~/Library/Application Support and checking to see if the TextExpander folder is an alias now.

On your other Macs:

  1. Install Dropbox and link it to the account you set up on your main Mac. The files you put there on your main Mac will now appear there automatically, synching over the Internet.
  2. Close System Preferences
  3. Delete the ~/Library/Application Support/TextExpander folder.  Your TextExpander folder is already in your Dropbox, so we just need to symlink to it like we did on the primary machine. (If you don’t like the idea of deleting the folder just rename it.)
  4. Open a terminal window and type the following command “ln -s ~/Dropbox/Library/TextExpander ~/Library/Application\ Support/TextExpander”

As on your main Mac, you won’t get confirmation in Terminal but you can check by looking in ~/Library/Application Support, where you should see TextExpander as an aliased folder.

On Windows:

  1. Install the Windows version of Dropbox and link it to the account you set up on your main Mac.
  2. That’s really all you need to do here. If you output your .ahk AutoHotKey script file to your Dropbox folder it will be available directly on your Windows machine without any copying etc.
  3. You may also want to put a shortcut to your *.ahk file in the Startup folder on in your Windows Start menu, then your snippets will be loaded automatically every time you start Windows

Leave a Reply