My apologies if this has been answered before / can be found in the documentation; I didn’t.
I am using a text expansion tool that I’d like to get rid of and import all my shortcuts into Keyboard Maestro, my preferred tool for, well, everything.
Unfortunately, it’s a lot of Macros – more than 1000, many of them multi-line. And with so many items, I’d obviously like to avoid manual post-processing or one-by-one creation.
(I realize people may chime in and say “Stick with your other text expansion tool”, but I’d really like to put everything in KM. Simple one-step expansion without variables, cursor insertion etc. is good enough for me.)
So – if I prepare these text snippets e.g. in a spreadsheet and export them to a clean text file (tab oder comma-separated), with columns for…
Macro shortcut (for “This string is typed”) trigger
Macro (plain text) content (for action “Insert text by PASTING”)
…what would be the best approach for such a large batch-import into KM?
I don’t mind if they all end up in the same folder (actually, that would be preferred), I can take it from there.
Unfortunately, I don’t know any AppleScript, which would probably be helpful here.
(I also just saw that I had started a thread with similar questions back in 2014, but this was focussed on TextExpander, and it didn’t really go anywhere, so I’m not reviving it.)
I looked at your 2014 post out of curiosity and noticed that Peter Lewis had created/posted a macro to take a list of text expansions and automatically create KM macros out of them. His macro can be found here:
Thanks; I have missed this. Unfortunately, it’s not what I’m looking for. It seems this will allow creation of single macros in KM. I was looking for a way to batch-import a large set (CSV or tab just seem like good formats for this) that obviously would need to be parsed / split in some manner during import.
The macro actually creates a new text expansion macro for every line you supply in the variable Expansions; so if you have 600 lines in there it would create 600 separate macros. It places each of those in a macro group called Text Expansion. You'd know this already if you'd tried running Peter's macro.
Here's my version that allows you to specify the name of each text expansion macro that is created. Be sure to read the comment and edit the two red-coloured variables according to your needs.
Perhaps worth pointing out the every macro created will have "Exact case", "Diacriticals matter", and "Only after word break" set as trigger options. If that's a problem, @thatguyinberlin, you might be able to add extra columns to your CSV and alter the macro so it can pick and choose -- or edit @tiffle's macro to produce your most-required options so you can reduce the manual snagging required later.
I wanted to add to this Feb. 2023 thread to help the next guy who comes along and needs to import a few hundred (or thousand ) text macros from a legacy tool into Keyboard Maestro.
So Peter N Lewis was kind enough to write a text import Macro in 2016, modified by tiffle, and I finally got around to migrating my 1250 macros (from aText, via Google Sheets for some cleanup work) to here.
It works, but there are a few caveats / things to consider:
If the macros you import contain certain (XML) characters or strings, they need to be escaped, or there will be errors. In my case: “<” as “<”; “>” as “>”, “\r” as “\r”. I’m sure this can be added to the Macro itself, but I prepared my import file accordingly outside of KM.
I also added the expansion character that I want to trigger every macro externally, so “kr#” expands to “Kind Regards” right away. Again, this might be added to the import routine itself.
Multiline text expansion: I replaced every carriage return in the source with a placeholder (“@@@”) and replaced this by %Return% in the import For loop.
I also added categories to the macro names (“Phone numbers: landline”), so it’s easier to retrieve/find them when I have forgotten a key combo.
I have some very long snippets, so I chose “Insert text by pasting”. YMMV.
My KM file now has grown from 300 to 600 kB (not really a big deal in a time of terabyte SSDs), everything works fine, and now my too arsenal has shrunk from three to two (Keyboard Maestro and ObDev’s LaunchBar). Couldn’t be happier.