Writing to NSUserDictionaryReplacementItems with defaults The following command reads the NSUserDictionaryReplacementItems. The keys are called Text Shortcuts in OS X.

defaults read NSGlobalDomain NSUserDictionaryReplacementItems


I want to create new shortcuts using the defaults command, because plists in Mavericks are now cached (and for various other reasons). As you can see from the output of the command above, it lists other keys and values. How would I access the keys and values within the main NSUserDictionaryReplacementItems key? The man page for defaults doesn't say how (or if) that can be done.
Different ways to add a replacement:

defaults write -g NSUserDictionaryReplacementItems -array-add '{on=1;replace=a;with=b;}'

defaults write -g NSUserDictionaryReplacementItems -array-add '&lt;dict&gt;&lt;key&gt;on&lt;/key&gt;&lt;integer&gt;1&lt;/integer&gt;&lt;key&gt;replace&lt;/key&gt;&lt;string&gt;a&lt;/string&gt;&lt;key&gt;with&lt;/key&gt;&lt;string&gt;b&lt;/string&gt;&lt;/dict&gt;'

Different ways to replace the whole list:

defaults write -g NSUserDictionaryReplacementItems -array '{on=1;replace=a;with="b \"\\b";}' '{on=1;replace=c;with=d;}'

defaults write -g NSUserDictionaryReplacementItems '({on=1;replace=a;with="b \"\\b";},{on=1;replace=c;with=d;})'

defaults write -g NSUserDictionaryReplacementItems '&lt;array&gt;&lt;dict&gt;&lt;key&gt;on&lt;/key&gt;&lt;integer&gt;1&lt;/integer&gt;&lt;key&gt;replace&lt;/key&gt;&lt;string&gt;a&lt;/string&gt;&lt;key&gt;with&lt;/key&gt;&lt;string&gt;b "\b&lt;/string&gt;&lt;/dict&gt;&lt;dict&gt;&lt;key&gt;on&lt;/key&gt;&lt;integer&gt;1&lt;/integer&gt;&lt;key&gt;replace&lt;/key&gt;&lt;string&gt;c&lt;/string&gt;&lt;key&gt;with&lt;/key&gt;&lt;string&gt;d&lt;/string&gt;&lt;/dict&gt;&lt;/array&gt;'

Quit and reopen applications to apply changes. 

Edit: the changes made with defaults are lost if you open the Text tab of the Keyboard preference pane. To prevent it, use a script like this:

date=$(date +%s)
while read -r replace with; do
  plist+="{on=1;replace=\"$replace\";with=\"$with\";},"
  sql+="INSERT INTO 'ZUSERDICTIONARYENTRY' VALUES($((++i)),1,1,0,0,0,0,$date,NULL,NULL,NULL,NULL,NULL,\"$with\",\"$replace\",NULL);"
done &lt; &lt;(sed 's/\\/\\\\/g;s/"/\\"/g' ~/replacements.txt)
sqlite3 ~/Library/Dictionaries/CoreDataUbiquitySupport/$USER~*/UserDictionary/local/store/UserDictionary.db "delete from ZUSERDICTIONARYENTRY;$sql"
defaults write -g NSUserDictionaryReplacementItems "(${plist%?})"


The replacements are saved to ~/Library/Dictionaries/CoreDataUbiquitySupport/$USER~*/UserDictionary/local/store/UserDictionary.db even if iCloud is disabled.