Create Text Expansions Macro

Thanks for the link. Gonna go through that if I have some spare time. Actually I bought typinator as well (and I do not understand everything, BUT the thing with regular expressions is HUGE).

A word of caution regarding Typinator. I used to use it, switched to TextExpander for a change in interface. Went back to Typinator today.

My OS went crazy. It seems that TotalSpaces2 conflicts withTypinator to the point that I had to disable TotalSpaces2. Use caution if you have both apps installed.

Hi, I'm a beginner to Keyboard Maestro, and am missing something simple about making OP's macro work. Can anybody offer some advice?

I'm not sure what OP means by

"simply fill in the text of the action with lines like:

trigger:text

where trigger is the Typed String trigger you want and text is the text you want to expand to."

I have tried to write in my trigger and text in different locations in the actions, but i'm not sure where in the actions it should go (i have tired the (.?):(.) area alot but not sure if i should be including the extra stufff). everytime i get a notification that says macro cancelled (pic below). Can anybody point me to exactly where i need to type the trigger and text? thanks so much!

This means, in the below Action, to replace the text of the Action with the text expansion trigger, and the text (snippet) that it will output, with your own, using the format of:
<trigger>:<text>

where
<trigger> is the typed string you will use to trigger the macro
<text> is the text snippet to be output

In the above Action, one of the macros to be created has
the <trigger> is "=em="
the <text> is "support@stairways.com"

Make sense?

1 Like

Yes!! makes complete sense now, thanks so much!

1 Like

(Only just on topic but) What interested me (apart from the whole confecting XML thing) is the use of a terminating character in a trigger.

For example, the second ‘=‘ in ‘=em=‘. It hadn’t occurred to me to use a terminator to aid disambiguation.

It also got me to thinking the technique of using Keyboard Maestro to confect other XML is great. For example, for z/OSMF workflows. (And then there’s confecting HTML.)

1 Like

Would love to know more about this... I assume you have some kind of system for these that makes them easy to generate/recall?

2 Likes

Hey Jon,

Many of those are spelling corrections that I don't need to remember.

I do make extensive use of sub-searches in Typinator, and in some circumstances I use key word/codes to make things easy to find.

Here's an example of the latter:

"h" is the sub-search code which is a mnemonic for "handlers" (my AppleScript handlers).

The prefix code identifies which library the handler is in.

So "h flb perl" will find any handlers that use Perl in my AppleScript "Find" library.

I use categories and sub-searches whenever something is likely to be hard to find.

I have something over 80 categories:

The "Date Strings" example above uses "ds" as its sub-search ID:

image

So it's easy to get there and find what I'm looking for (if I forget my direct abbreviation):

-Chris

7 Likes

Hey Chris, good to see you!
Great system! :+1:

1 Like

I'm populating the Expansions variable using the Read file to Variable action. This allows me to maintain and reference my list of text expansions in the text system of my choice -- currently Obsidian :tada:.

When I run the Create Text Expansions macro again I of course get duplicates created in my KM library. I'd be fine with automatically deleting all the expansions each time since the KM macro will add them back again, but I don't see any way to have a macro delete another macro.

Suggestions on the best way to handle this?

You can use AppleScript to delete all the macros within a specific macro group.

I suggest before running such a macro, you quit and relaunch the Keyboard Maestro editor, that way you have File ➤ Revert Macrs ➤ At Editor Launch available should you accidentally make a mess of your macros.

tell application "Keyboard Maestro"
	delete every macro of macro group "MACRO GROUP NAME"
end tell
1 Like

Perfect, thanks! Below is my working version of it all.


Create Text Expansions PUBLIC.kmmacros (6.3 KB)

1 Like

@peternlewis Thanks for sharing this. You mentioned this thread in another thread that I had posted. Migrate Typinator Snippet to Keyboard Maestro

I started using this macro to migrate a few of my Typinator snippets and I'm facing a hurdle. Although the keyword and snippet expansion works fine overall and in isolation, when multiple triggers are met, I see an issue.

For example, I have a macro created which capitalizes the first letter of each word in a sentence. And I also have text expansion snippets. For example, when I type abso, it translates to absolutely. Now when I type abso in isolation—not as a new sentence—it expands properly. But when that is the first word in a new sentence, because both macro triggers are being met, only the first-letter-capitalization one works and the other does not. so it becomes Abso. What I would want it to become is Absolutely.

How can i accomplish this? Can you please help me with this?

:backhand_index_pointing_down: This has the normal text expansion snippets and the first letter capitalization macro.

Text Expansion Macros.kmmacros (6 KB)

No idea I'm afraid.

Simulating characters resets the Typed String buffer.

The only way you could do it that I can think of would be to have your capitalization macro also do any expansion necessary as well.

But I wouldn't be trying to use Keyboard Maestro to do capitalization for you.

Gotcha. So does Keyboard Maestro not support two string triggers at the same time - One regex and one absolute string? because that is my use case.

I think this is mostly a priority issue where the autocap needs to run after the usual expansion but that isn't how KM is behaving.

But the autocap won't run after the usual expansion -- KM-typed characters don't go into the typed string buffer so aren't analysed for potential typed-string triggers.

Imagine if they were -- you type in "abso", KM starts to expand that to "absolutely", as soon as it reaches the "o" there's a trigger match so it starts to type in "absolutely", as soon as it reaches the "o" there's a trigger match...

I think the best way round your problem is to save "naked" triggers for spelling corrections (including capitalisation) and use a prefix on your expansion triggers. As the "Typed String Trigger" Wiki page says:

To avoid macros firing unexpectedly it is a good idea to include a consistent prefix and/or suffix to your strings. For example, to insert your email address, rather than use just “em” (which would fire if you typed “them”), use something like “=em=” which you will not type accidentally.

I wrap mine in ; since that's not a character I'd normally type without a space following it and I like to have a terminator to make regexing easier, so I'd use ;abso;. But pick whatever is easy to type and works for you.

If two triggers were fired at the same time, then Keyboard Maestro would ask you which to perform.

For example:

If you type “wxxx” it would trigger the first macro.

If you type “what” it will show a Conflict Palette and ask you which to trigger.

Keyboard Maestro will trigger the longest matching text string, and if there is more than one, then ask you which one you want to trigger.

It will not trigger both.

1 Like

But I wouldn't be trying to use Keyboard Maestro to do capitalization for you.

That is the only feature I need—to consolidate everything to KM—apart from the usual snippet expansions. The snippet expansions work fine in KM, as I mentioned, but I don't want to keep capitalizing the first letter of every sentence. I just want my snippet expander to handle that.

My primary reason for moving to Keyboard Maestro is that it lets you open user input forms and other things, and the automation ecosystem is much easier. With Typinator it is really cumbersome.

Can you suggest how I can create a separate first‑letter‑capitalization macro while keeping the expansions as simple as just keyword > snippet mapping?

Have your capitalization macro also perform any necessary expansions.

I couldn’t think how this would work, which is why I've been asking again.

The only way I can imagine this working is to have the macro that does the capitalization to also look at the word it is caplalizing and check it against a list of all your snippet mappings and if there is a match, translate the word as well as capitalizing it.

So for example, when you decide to capitalize the first word, you then check if the first word is abso and if so replace it with Absolutely.

So basically you'd need a macro that triggers whenever you type any first word or any not-first word, and then do the translation of both the capitalization and the expansion.

As I said, I wouldn't be trying to use Keyboard Maestro to do capitalization for you.

If you want that facility, I'd suggest using a text expansion specific application designed for that purpose.

1 Like

macOS also allows for automatic capitalization. This includes the first word of sentences, and it also includes other word which get capitalized, like proper nouns. That may or may not be wanted.