macOS > Settings > Keyboard > Text Replacement is a macOS/iOS feature I use extensively but it is unavailable in quite a few macOS applications — including some Apple apps like Xcode. Other apps I want Text Replacement to work in but it doesn't are the Adobe CC suite, all my code text editors like VC Studio, Sublime Text, BBEdit, emacs etc and Firefox.
Does anybody know what the file path is for the file that stores the Text Replacement key/string pair data?
If i can access the .plist file or similar where the Text Replacement key/string pairs are stored I will be able to convert to JSON using REGEX and import to the Firefox plugin that will replicate Text Replacement functionality in Firefox for me. Ditto other code editor applications with their own particular text substitution functionality.
Background
Some of these apps have plugins or functional equivalents of Text Replacement but i need a way to do the import/export dance to keep them in sync with my Text Replacement text pairs.
Sadly, even though we can select the Text Replacement table (in macOS but not in iOS versions), we can't copy that information. This seems to me a violation of good GUI design principles. Why allow selection of the entire table if we cannot copy it to the clipboard?
Nor can we import or export the table of text tuples. The Text Replacement GUI has no buttons to do this (consider this post also a FR for that).
Screen-capturing and running text recognition software over the PNG it is not an option given: a) all the UTF-16 unusual glyphs and combination glyphs i use; b) that I'd like to script this as a multi-directional syncing application I can run periodically.
Typically macOS and app preferences are stored in plist files. I want to find such a file and convert it to JSON for importing into a Firefox plugin that replicates Text Replacement within Firefox.
I tried modifying Text Replacements by adding a new item to the list and clicking "Done" and then filtering ~/Library for .plist files and sorting by "Date Modified" but nothing is showing up with these values in it.
Solution
In summary the relevant filepath is:
~/Library/KeyboardServices/TextReplacements.db
Extracting the data
to extract using sqlite3 (should be on macOS by default):
sqlite3 ~/Library/KeyboardServices/TextReplacements.db
Run the following commands to output the ZSHORTCUT and ZPHRASE to a CSV file:
.headers on
.mode csv
.output text_replacements.csv
SELECT ZSHORTCUT, ZPHRASE FROM ZTEXTREPLACEMENTENTRY;
.exit
Converting CSV to JSON
If you want to convert the CSV to JSON, you can either use a tool like jq or convert it with a Python one-liner (see attached text file).
python3 -c "
import csv, json
with open('text_replacements.csv') as f:
reader = csv.DictReader(f)
print(json.dumps(list(reader), indent=4))
" > text_replacements.json
Use the correct field names
in my case I opened in a text editor and replaced all "ZSHORTCUT" with "repalce" and all "ZPHRASE" with "with" then imported the JSON file into the Firefox plugin called TextFast . all working now..
ChatGTP solved this for me
LINK to ChatGTP instructions:
https://chatgpt.com/share/6708a59e-7ccc-8006-b095-d6da9545f587
in case that link doesn't work in future i attached as text file.