# How can I export text substitutions from Lion for import into Mountain Lion

I am trying to migrate to a brand new install of Mountain Lion. I am trying to migrate select data from my old Lion install. Does anybody know where the text replacement definitions in System Preferences > Language & Text > Text lie? I would like to migrate them to my Mountain Lion install.

-

Thanks to Sacrilicious identifying the actual file/key where the data is stored, I figured out how to copy the whole thing with a few Terminal commands.

Make sure you don't have System Preferences open while doing this, or it may not work!

1. On your old install, run /usr/libexec/PlistBuddy -x -c "Print NSUserReplacementItems" ~/Library/Preferences/.GlobalPreferences.plist > backup.plist
• This saves the substitutions to the backup.plist file in whatever directory you ran that command from (by default, your home directory).
2. Copy that backup.plist file to your new install (I recommend your home directory for simplicity).
3. On the new install, run /usr/libexec/PlistBuddy -c "Delete NSUserReplacementItems" ~/Library/Preferences/.GlobalPreferences.plist, then run /usr/libexec/PlistBuddy -c "Add NSUserReplacementItems array" ~/Library/Preferences/.GlobalPreferences.plist
• This wipes the default substitution list and creates a new blank one.
4. Again on the new install, run /usr/libexec/PlistBuddy -c "Merge /PATH-TO-BACKUP/backup.plist NSUserReplacementItems" ~/Library/Preferences/.GlobalPreferences.plist, first replacing the /PATH-TO-BACKUP/backup.plist part with the actual path to wherever you saved the backup file.

That should do it. Open System Preferences to double check, but you should have an identical copy of your text substitutions on your new install.

-
LIFESAVER. Thanks a million. –  finiteloop Jul 31 '12 at 17:28
This is a great answer to obscure problem… And to make it even better I whipped up a quick Automator app, "the Text Replacement Migration Assistant", lol, that makes it even easier. find it at github.com/mralexgray –  alex gray Feb 28 '13 at 1:25
Having issues like "Merge: Error Reading File:" (due to bash missing expansion) merging files with PlistBuddy from your user profile folder, check this example /usr/libexec/PlistBuddy -c "Merge '$(ls ~/Documents/OS\ X/common-typos.plist)' NSUserReplacementItems" ~/Library/Preferences/.GlobalPreferences.plist – Pro Backup Jul 28 '13 at 20:51 @ProBackup I suspect the error is due to the command expansion ($(ls ~/Documents/OS\ X/common-typos.plist)). You should just have a direct path to the plist file, i.e. /usr/libexec/PlistBuddy -c "Merge '~/Documents/OS\ X/common-typos.plist' NSUserReplacementItems" ~/Library/Preferences/.GlobalPreferences.plist. –  robmathers Jul 28 '13 at 23:04
“NSUserDictionaryReplacementItems” seems to be what you’re after for Mavericks, just in case anyone’s trying to do this on OS X 10.9. :) –  Marc Edwards Feb 14 '14 at 11:17

Programmatically speaking, each substitution is a dictionary written to the NSUserReplacementItems array at the root of the ~/Library/Preferences/.GlobalPreferences.plist file.

I'm not able to think of a simple way to move data, even with Xcode's Property List Editor, from 1. an invisible file 2. in a hidden folder 3. to a specific part of the new systems file. To get you started, you can read them all with defaults read .GlobalPreferences NSUserReplacementItems or, if you want to just pull one(the first I'm seeing that I just customized in Lion is located at index #15, therefore): /usr/libexec/PlistBuddy -c "Print :NSUserReplacementItems:15" ~/Library/Preferences/.GlobalPreferences.plist which would return something like this:

Dict {
replace = bIg
with = BigBabyBuggyBumpers
on = 1
}


And then writing the stuff back could be done in any scripting language that speaks apple's xml, or piecemeal with the trio of:

/usr/libexec/PlistBuddy -c 'Add :NSUserReplacementItems:16:on integer 1' ~/Library/Preferences/.GlobalPreferences.plist (which turns the checkbox on)

/usr/libexec/PlistBuddy -c 'Add :NSUserReplacementItems:16:replace string "bIg"' ~/Library/Preferences/.GlobalPreferences.plist

/usr/libexec/PlistBuddy -c 'Add :NSUserReplacementItems:16:with string "BigBabyBuggyBumpers"' ~/Library/Preferences/.GlobalPreferences.plist

I'll tweet it out, someone probably has the easier way and can chime in or build on this.

-