TL;DR: See the update at the bottom if nothing else.
For Mojave and Catalina... How to clear Text Replacements that refuse to be deleted, that do not sync to your iOS devices properly, or any other bug in the keyboard replacements you can't resolve by just using the System Preferences->Keyboard->Text user interface.
The text replacement database is stored here:
~/Library/KeyboardServices/TextReplacements.db
for the brave, you can open this with SQLPro for SQLLite or Valentina Studio (App Store links).
For the step-wise nuke from orbit, do this... (no data loss)
1 Backup your Text Replacements
- Open System Preferences
- Click Keyboard
- Click Text tab
- Click in list of replacements
- command + a to select them all
- Drag and drop to desktop (it creates
Text Substitutions.plist
- Quit (close) System Preferences
2 Fully Delete the Text Replacements
- Open "Activity Monitor"
- find
keyboardservicesd
and "force quit" it
- find
Keyboard Remote Service (System Preferences)
and "force quit" it
- in Finder Command + G
- Paste in
/Users/williamcerniuk/Library/KeyboardServices/
- Press "Go" button
- command + a to select all items in folder
- command + delete to put them in the trash
- (very important) delete ~/Library/Keyboard/textReplacements.cache
3 Restore Text Replacements Backup
Now here is the dicy part. The keyboard replacements you just saved off may actually have the problem in it, but try this anyway to get them back from the backup.
- Open System Preferences
- Click Keyboard
- Click Text tab
- Locate the file
Text Substitutions.plist
- Drag file
Text Substitutions.plist
into the empty 'replace with' list
Now your old text replacements have re-appeared and with any luck the problem you were solving has been solved. The Text Replacements will start to sync to your iPhone, iPad and or iPod touch.
Be aware, this last step (21) may just end up copying the problem right back in. If so then...
Surgery of file Text Substitutions.plist
may be necessary. Opening this file with any regular text editor enables you to hand modify it and remove entries until you can restore it and your problem is solved (presuming your problem exists at this point). Recommend using BB Edit from the App Store. Xcode has a nice editor but it is a behemoth-app and not worth downloading for this small task.
Update
A duplicate of the text replacements are stored in a hidden file in the system:
~/Library/Preferences/.GlobalPreferences.plist
with a plethora of other things. This file can be opened and manually edited if elements in the Text Replacements are not able to be removed per process above. Editing takes some technical savvy but can be done with BBEdit or Xcode. TextEdit tends to not be a good tool for editing plain text files.
3I've recently learned that this feature is only supported by some apps (e.g., Chrome does not support it currently). And for some that do like TextEdit, it may not be on by default (unless I disabled it at some point?). In the case of TextEdit, I had to enable it in that app's preferences ("Text Replacement" checkbox). The below command from @grgarside didn't enable this for some reason, but I didn't try an app restart, so maybe that's why. TIP: Spotlight works, so if you want to use a shortcut in an app without support, Cmd+Space to open Spotlight, type your shortcut, and copy/paste – Dolan Antenucci – 2017-03-02T16:37:06.397
Sometimes I have to select Edit / Substitutions / Text Replacement again in certain apps. For some reason it gets reset when I upgrade. – EricS – 2017-10-30T17:44:29.273