Save time with Keyboard Maestro and AppleScript
Earlier today, Shawn Blanc linked to the latest version of TextExpander, noting that it now supports AppleScript. I don’t disagree that TextExpander is a great app, but I prefer Keyboard Maestro—which has been supporting AppleScript for over a year now—and is a lot more powerful. You can get 20% off by clicking my affiliate link, thereby reducing the price to $28.80.
Having given my pitch, I’d like to delve into the original intent of this post: I have a solution for the feature request in Shawn’s aforementioned post. He’d like his string shortcut to paste a random variation of his “thank you” note. This can be achieved quite effortlessly with a text file, a script, and Keyboard Maestro. If TextExpander’s AppleScript support is as good as Keyboard Maestro’s, this solution should work for Shawn:
- Create a plain text file containing your variations, each on a separate line, and save it to your Desktop. I named mine “variations.txt”.
- Open AppleScript Editor and save a new script containing the following:
- set v to alias (“” & (path to desktop) & “variations.txt”)
- set theText to some item of (read v using delimiter linefeed)
- Open Keyboard Maestro Editor and add a new Macro with the following settings:
- Click on “New Trigger” and select “Hot Key Trigger” or “Typed String Trigger” depending on your preference. You can also add both if you want! I chose a hot key and assigned it to control-option-command-V.
- Click on “New Action” and double-click on “Execute an AppleScript” in the “Actions” pane.
- Click on “Execute text script” and select “Execute script file”.
- Click on the “Unknown” button and open the script you created a few steps ago.
- Click on “ignore results” and select “paste results”.
You should end up with something like this:
That’s it. You’re done. From now on, whenever you press ⌃⌥⌘V while in any text input field, one of your variations will automatically get pasted.

