Diferentes formas de añadir una sustitución:
defaults write -g NSUserDictionaryReplacementItems -array-add '{on=1;replace=a;with=b;}'
defaults write -g NSUserDictionaryReplacementItems -array-add '<dict><key>on</key><integer>1</integer><key>replace</key><string>a</string><key>with</key><string>b</string></dict>'
Diferentes formas de sustituir la lista completa:
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 '<array><dict><key>on</key><integer>1</integer><key>replace</key><string>a</string><key>with</key><string>b "\b</string></dict><dict><key>on</key><integer>1</integer><key>replace</key><string>c</string><key>with</key><string>d</string></dict></array>'
Salga y vuelva a abrir las aplicaciones para aplicar los cambios.
Edición: los cambios realizados con defaults
se pierden si se abre la pestaña Texto del panel de preferencias Teclado. Para evitarlo, utilice un script como este:
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 < <(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%?})"
Las sustituciones se guardan en ~/Library/Dictionaries/CoreDataUbiquitySupport/$USER~*/UserDictionary/local/store/UserDictionary.db
incluso si iCloud está desactivado.