Is it possible to programmatically access and manipulate the native text replacements of macOS? If so, what are the APIs or methods to achieve this, considering the sandboxing and privacy restrictions in the latest versions of macOS?
Direct Access to macOS Text Replacements
Text replacements? Please elaborate.
I’d like to clarify two things:
-
You’re talking about the list of replacements in System Settings > Keyboard > Text Replacements, right?
-
What do you mean by “programmatically access and manipulate”? I suspect that you’re looking for an API to a) enumerate the current list of replacements, b) modify an existing one, c) add a new one, and d) remove an existing one. Is that right?
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
I would like to simply access a .plist
file (or similar) with the existing user defined Text Replacement settings.
For context, I'm an extensive user of this feature, and use macOS to add shortcuts for text glyphs and take advantage of the fact that it will synch to my iPhone and iPad. seeing as the iPhoneOS and iPadOS implementations of "Text Replacement" settings don't easily facilitate the use of non-ASCII glyphs, especially non-UTF-8 Gylphs (there's more to advanced glyphs than emojis Apple!).
many Application developer on macOS have not provided support for the system level "text replacement" settings to work in their app, notably, all the Adobe CC apps, FireFox and a bunch of text editing applications like Xcode(!?), Sublime, Visual Studio Code, macvim, emacs.
Fortuately some of these apps have their own text conversion functionality or plugins. The issue is exporting the 100+ shortcuts I have in my macOS System settings to some kind of JSON or CSV file for importing or pasting into these other apps and plugins.
For instance there's a Firefox plugin that can import a JSON file of strings tuples.
Unfortunately, Apple engineers have made it impossible to simply select all of the string pairs in Settings> Keyboard > Text Replacement and then use the Copy and Paste commands to etract the text I need.
I probably could have manually type these 100+ codes out in the time I've spent on the phone to Apple and researching this issue online without any luck. But I'd like an answer to this conundrum as I'll need to keep exporting the list going forward.
If there is some kind of way to access this info and export/import it from macOS I could write a script to automate two-way or multi-node syncing of the text pair tuples between all my apps. (please not via AppleScript, its such a confusing language for occasional users) .
I even considered processing a few screenshots of the text replacement fields using Adobe Acrobat text recognition software, but many of the gylphs I use are mathematical and combination diacritics symbols (UTF-16) etc and I don't think Acrobat will do to well on it.
Thank-you.