8

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.

3 Answers 3

10

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.

4
  • 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
    Commented Feb 28, 2013 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
    Commented Jul 28, 2013 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
    Commented Jul 28, 2013 at 23:04
  • 1
    “NSUserDictionaryReplacementItems” seems to be what you’re after for Mavericks, just in case anyone’s trying to do this on OS X 10.9. :) Commented Feb 14, 2014 at 11:17
1

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.

1

I found an easier way to do it.

Use these steps to export your existing text substitutions: - Open System Preferences > Keyboard > Text.

  • Select the shortcuts you want to export. If you want to export all of your text substitutions, select one of them, then choose Select All from the Edit menu.

  • Drag the selected shortcuts to the desktop. This creates a file name Text Substitutions.plist that contains the substitutions you selected.

  • Close the System Preferences window.

Use these steps to import the plist file you created in another user account: - Copy the plist file you previously created to the /Users/Shared/ folder, or to an external drive.

  • Log in as the user account where you want to use these text substitutions.

  • Open System Preferences > Keyboard > Text.

  • Drag the Text Substitutions.plist file to the area of the System Preferences window where the text substitutions are shown (under Replace or With).

  • Close the System Preferences window.

source: https://support.apple.com/en-us/HT204006

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .