macOS Text Replacement Export/Import Works Great Until It Doesn’t

Originally published at: macOS Text Replacement Export/Import Works Great Until It Doesn’t - TidBITS

Does everyone reading this know that Apple has long provided basic text expansion capabilities in macOS, iOS, and iPadOS? You’ll find them in System Settings > Keyboard > Text Replacements on the Mac; in iOS and iPadOS, go to Settings > General > Keyboard > Text Replacement. In each, a text replacement consists of a shortcut and a replacement phrase. Type the shortcut, followed by a space or a punctuation character, and its phrase will replace it.

Text Replacements dialog on the Mac

Text expansion is a great way to speed up typing of email addresses, frequently used URLs, emoji and special characters, hard-to-type words, complex Unix commands, and chunks of boilerplate text. It’s also excellent for automatically fixing common typos—if you regularly type “teh” instead of “the,” a text replacement can fix your finger fumbles.

What I didn’t know until recently is that Apple provides a hidden—but documented, amazingly!—way to export your replacement pairs to a property list file. All you have to do is select the items to export (Command-A selects all) and drag them to the desktop. You can then edit that file in a text editor like BBEdit or TextEdit before reimporting it, which is merely a matter of dragging it back into the Text Replacements dialog. This export/import feature is useful in three ways:

  • Backup: If you have an extensive set of text replacements, making a backup would be a sensible precaution.
  • Sharing: Any Mac user can import your text replacements, so if you’ve built up a custom collection of scientific, medical, or technical replacements, you can share them with colleagues.
  • Easier editing: Bulk changes might be easier to make outside Apple’s one-at-a-time interface.

The TidBITS AutoCorrect Dictionary

Once I realized I could import text replacement pairs, I had another thought. If you had a large list of typos and the correct versions of their associated words set up as text replacements, you’d likely end up with many fewer typing mistakes in your documents.

Where would you acquire such a list of typos? Over 25 years ago, for the MacHack developers conference, I created the public domain TidBITS AutoCorrect Dictionary, based in large part on a word list from then-Princeton student Micah Alpern (see “An ATypoKill Eudora Hack,” 4 September 2000). It contains over 2700 pairs of misspelled or miscapitalized words and their correct replacements.

Years later, it was integrated into Typinator (see “TidBITS AutoCorrect Dictionary Enhances Typinator,” 27 August 2007), TextExpander, and TypeIt4Me (see “TidBITS AutoCorrect Dictionary for TextExpander and TypeIt4Me,” 10 September 2007).

Several years after that, Apple added text replacement capabilities to Mac OS X 10.6 Snow Leopard. Longtime TidBITS Talk contributor Lewis Butler wrote an article about how to integrate the TidBITS AutoCorrect Dictionary in “Improve Snow Leopard’s Autocorrection Capabilities” (16 September 2009). (Sadly, Lewis died unexpectedly in January 2022.) He discovered that Apple stored the text replacement list in an invisible file at ~/Library/Preferences/.GlobalPreferences.plist and then figured out how to convert the TidBITS AutoCorrect Dictionary to use the appropriate data structure. It worked, but required a complicated manual integration process.

A Rabbit Hole of Twisty Little Passages, All Different

I was all ready to give you an updated version of the TidBITS AutoCorrect Dictionary that could be imported into the Text Replacements dialog, but after hours of testing, I just couldn’t make it work reliably enough. Some of the problems I encountered included:

  • An unhelpful error dialog appeared when importing a file containing “too many” entries, though I never figured out what “too many” meant. In some cases, I could dismiss it and see the replacements. In others, I had to force quit System Settings and start over.
    Error in Text Replacements import
  • Sometimes, after an import, most or all of the imported entries would appear. Other times, the Text Replacements list was zeroed out. In one early test, when the imported entries did appear, I exported them, cleared the list, and reimported, only to get the error again. So an export/import pass didn’t fix the file.
  • Sometimes, the Text Replacements dialog wouldn’t accept a dropped file for import on the first try but would on a subsequent try. Quitting and relaunching System Settings sometimes made a difference, but not always. Restarting might have helped, but it’s also possible that iCloud syncing was getting in the way.
  • A binary search approach (splitting the file in half and halving it again) didn’t identify any corrupted entries, nor did removing a few entries that Claude and ChatGPT agreed were iffy because they contained double quotes. Sorting all the entries alphabetically made no difference. Splitting the file into smaller pieces sometimes worked, but a file containing 1000 entries imported unpredictably. Imports usually (always?) worked with files containing just 100 entries, but I don’t know if they would have failed when the total number exceeded some threshold.
  • iCloud syncing seems to have thrown up its hands at some point, so although I was able to delete all the failed tests from both of my main Macs and reimport my original handful of text replacements, my iPhone still contains the full set from one of the early imports that worked but crashed System Settings. I don’t know if they’ll all catch up with each other eventually.
  • I tried adding my entries to the invisible .GlobalPreferences.plist file, but macOS silently deleted them as soon as I opened the Text Replacements dialog.

In short, I give up. But in the interest of science, where negative results can still advance the field, I’m making my reformatted and ready-to-import TidBITS AutoCorrect Dictionary available for download again. I suspect Apple never tested its import or syncing code with a file containing so many entries, but someone else may be able to devise a workaround that addresses the limitations without being too onerous. If you figure out a reliable method, let us know in the comments.

Of course, the easiest and most reliable workaround is to stick with TextExpander, Typinator, or TypeIt4Me, all of which properly handle very large numbers of replacements and already include the TidBITS AutoCorrect Dictionary. This is why we have independent developers!

6 Likes

A blast from the past!!! I remember using this and apparently forgot about it when I discontinued TextExpander.

I’m curious if the AutoCorrect Dictionary can be imported into Alfred, my current “snippet” companion to the macOS Text Replacement.

Curious question: Does anyone know if any of these apps work with dictation? I’m reading an old county court order book into BBEdit, and could make use of this to auto replace one particular word that dictation almost always gets wrong.

I never figured out what “too many” meant

At one point, a few years ago, I had to move most of my bookmarks from Safari into Raindrop because Safari kept rearranging them whenever it attempted to sync. I think I had about 300.

Although I have only ever had one Apple account, iTunes/Music stopped synching years ago — when I play music on my phone, as I often do to my kitchen Home Pod minis, only the first song I play shows up as recently played in my music library. This, of course, ruins the reliability of smart playlists that include recently-played rules (just as Apple’s way of applying star ratings to unrated tracks in an album made shuffling by star rating impractical). My music library has about 12,000 songs.

It would be nice if Apple would publish the limitations of its synching systems, but it seems that they would rather a few users be frustrated than to admit to all users that their products have limitations at all. I’m not bitter, not cynical, just disappointed.

It’s good Adam is reminding us of this – since being dedicated to TextSniper on the Mac (which I heartily commend) I’ve been forgetting…

I prefer Keyboard Maestro. I’m not familiar with the packages mentioned in the article, but Keyboard Maestro is so flexible and powerful it’s covered everything I’ve thrown at it.

1 Like

It would be wonderful to find an app such as textexpander et al that works both on the mac and iOS.

Tommy

Adam,

Nice reference to the ORIGINAL text game, “Adventure” (sometimes called “Colossal Caverns”.) I first played it at the Stanford AI lab back in the 70’s or 80’s on a PDP-10. The folks at the lab said it would NEVER run on a personal computer. True under CP/M! Pre-Zork!

Ron

1 Like

Raycast syncs between both, but the iOS experience is a little different. For macOS I type the expansion code like you know, but in iOS you can use the Raycast keyboard to find and paste the snippet.

I think the only text replacement I have in macOS/iOS is the “@@” to splat my primary email. I rarely use iOS snippets. On macOS everything is done with Raycast, including emojis, and both simple and complex text replacements.

I thought I knew, but I’ve gone looking for it a couple times lately and not found it.

Now I remember why I didn’t bother to remember where it was. It can’t do what I want to do. Do any of the third-party apps support variable replacement, such as some escape-character-variable (##date or ##time for instance)?

Thanks.

Keyboard Maestro.

Dave

1 Like

In the Japanese macOS, it is called System Settings > Keyboard > User Dictionary….
User Dictionary for text input has existed from the beginning of Japanese OS, at least from System 6.0.7/KanjiTalk and System 7/WorldScript of 1990s. Dictionary is an essential part of Japanese text input, where we type phonetic expression on the keyboard, and then the OS instantly translates it into Kana/Kanji characters onscreen. An advanced, self-learning System Dictionary is built into the OS, but User Dictionary is a natural and essential method for user to manually customize the System Dictionary.

2 Likes

I’ve tried relying on just the built-in macOS text replacement system in the past, but keep finding enough edge cases where it doesn’t work to justify the continued use of Typinator.

Judging by the error messages and other things you came across, Adam, I can only surmise that macOS (and iOS/iPadOS) text replacement wasn’t designed for intensive use. :person_shrugging:

(I also have Keyboard Maestro, but I find Typinator easier to work with when it comes to text expansion. YMMV, of course, that’s just my preference.)

1 Like

It certainly should be possible. I don’t know what the format Alfred needs is, but ChatGPT or the like should be able to reformat the document for you.

I don’t believe so. The problem is that dictation won’t let you enter incorrect words, and all the shortcuts are incorrect by definition.

Glad you noticed it! I loved Adventure.

I’m pretty sure TextExpander and Typinator can both do that and a lot more, thanks to scripting support.

This is interesting. When I dictated “I guess I will have to continue replacing Kort with court.” here, the k o r t word was changed to court; but when I dictated it in BBEdit, the misspelling remained, and I was able to copy it over here. I do have it set up in text replacement.

Because it is supported on iPadOS & MacOS, I use Text Replacement extensively for

  • email addresses (I’ve got six I use often)
  • web domains: ,,tbl expands to .tumblr.com, so it’s easier to visit the home pages of tumblr users (leaping the algorithms)
  • psuedo references: &shrug; expands to \_("/)_/
  • bypass autocorrect censorship: fink expands to fink

Alfred does (and it calls text replacements “snippets”)

Everyone currently in my household (me) knows. Been exploring it more since TextExpander went subscription model. These days it suits my minimal expansion needs. Sometimes I set up Replacements and later find it takes more time to remember the shortcut than typing from scratch, since I’m not using them often enough.

I also did not know about the export and other options, thanks very much for pointing them out!

I’ve also wondered how dicey it would be to use them for say username-password combos on a device that rarely leaves the home but connects online over wifi. That is, could automated or human attackers find and use combos over the internet (all bets are off if device is stolen of course).

The ‘documented’ link @ace shared (and others) indicates the replacements can be used across Apple Devices if the user is signed into the same Apple Account and uses iCloud Drive. Which is of course different from say, exporting them on Mac and importing resulting file to say, an iPad over AirDrop or via usb chip-Files App. Although Apple vaguely states on the page “You can also send it to another person to share it with them”.

I wish Text Replacement did, but LauchBar does. I often rename files with a shortcut for the date, which worked with TextExpander simply by typing the shortcut text. I haven’t found this functionality in Text Replacement yet. With LaunchBar, invoking the App thru its shortcut, followed by the desired textual shortcut and Enter, is a few more steps and so not so worthwhile in this case but it could also be used for more demanding and perhaps multiple expansions (see Snippets & Placeholders).

I always spell out Time Machine because otherwise ™. I used to go to Apple Developer conferences, where Q and A sessions would bring up programming holes or workarounds. From those sessions, I believe what you really meant to say is:

Replace ^ With

This is why we have independent developers! This is a Developer Opportunity!