MacOS – How to export Text replacements from the Keyboard System Preference from shell

automatormacosplistsystem-prefs

There are a few users here that use the same replacement text between several machines. We'd like to be able to sync up the replacement table between the systems.

Right now the manual way of doing this consists of selecting all items from System Preferences -> Keyboard -> Text entries on the table below this tab and then drag them out to Finder. Here's the table I'm talking about:
example

This creates a plist that can then be shared and dragged back onto this table for importation.

I suspect that there's a way to manually capture the plist or a portion of this configuration wherever it exists and then simply set up a sync script that keeps us all in sync every day.

EDIT: For what it's worth, I did a little digging and found that these values are stored in ~/Library/Preferences/.GlobalPreferences.plist. If you look you'll see these stored in the NSUserDictionaryReplacementItems key.

I found that you can pull out these keys with the following command:
/usr/libexec/PlistBuddy -c "Print :NSUserDictionaryReplacementItems" ~/Library/Preferences/.GlobalPreferences.plist

So now it's going to be a matter of storing these and reinserting them into another system's plist key.

Any ideas on how to do this manually from the shell so as to be able to automate?

Best Answer

There is an unofficial command line tool, which does exactly what you want, its called shortcuts. As mentioned on GitHub, you can install it via homebrew

brew install rodionovd/taps/shortcuts

and then list your current replacements via

shortcuts read

and add new ones via

shortcuts import <input.plist>
shortcuts create <shortcut> <new phrase>
shortcuts update <shortcut> <phrase>
shortcuts delete <shortcut>

for details, see the documentation.