Simple text expansion in KM or Alfred?

My text expansion needs are pretty simple. I moved most over to default Apple’s default text expansion. However, I have one that I still use an old version of Text Expander for. If I can replicate this in Keyboard Maestro or Alfred, I can do away with TE so I’m wondering if this is possible.

When I type in x.sub, it expands to ‘November 2019 Invoice’, where November is derived from taking the current month and going back one month and it pulls the current year. (I run this expansion in the first few days of the month like December so the invoice is for November work.)

Is this possible to do in KM or Alfred?

Here’s how you would do it in KM:

If you type x.sub, it is replaced by November 2019 Invoice.


Wow, thanks, @JohnAtl.

I tried it and for some reason, nothing is happening. I’ve triple checked my macro which is attached. I feel like I’m missing something really stupid here.

probably a variable setting thing. I am sure @JohnAtl will explain.
Myself I would just leave out setting the variable and into the insert text by typing box just use what you had put in the variable. I am not sure why John set it to a variable. I do this using Keyboard Maestro and don’t set it to a variable. There might be a reason for saving plist space or something if you have a lot of macros.
Just do it direct I would, write what you have and add ‘Invoice’. I will try it to see if it works and I haven’t missed anything myself.

%ICUDateTimeMinus%1%Months%MMMM yyyy% Invoice

Thanks, @TudorEynon. That didn’t work for me either. I then also made it a status menu item and neither worked. (I did a double check that other menu items were working just to make sure something weird wasn’t happening. Other macros are working.)

For Alfred, you create a Snippet:

Make sure auto-expansions are enabled for Snippets, and it is also enabled for this particular Snippet.

Good call. I don’t do this that much, so just googled around and winged it.
Not sure why it isn’t working though, unless it’s in a group that is only active for certain applications. Hm…

1 Like

It resides in My Macros folder which is available in all apps, windows, and always activated. Strange.

Thanks, @tomalmy. Long story but I don’t have access to the Alfred Powerpack right this second but this seems like a very simple solution.

One other thought with the KM macro: I have had the situation come up where I was editing a KM macro, and it simply did not execute as expected. When I created a new version of the macro from scratch and rewrote all the elements of it, it then worked. Somehow the first version got “wedged” and did not work, and I could not figure out why. This has happened to me a few times, so it might be worth a try for you.

That being said, I also use Alfred for my snippet expansions. In the cases where I need to do date calculations that are beyond what Alfred’s built in date calculation features can handle, my approach is to create a workflow using a snippet trigger. I can then attach a script in the language of my choice to generate the needed output.

For example, I frequently need a date string in the form of yyyy-mmdd where mmdd is the last day of the previous month (think bank statements). There may be a way to do that built in to Alfred but I could not figure it out (since the dd part is obviously dependent on the number of days in the previous month, taking into account leap years), so I just generated the proper date in a script instead.

You can do the same things in KM, but I remember reading somewhere a posting (I think attributed to KM’s author, but I could beg wrong) saying that KM works well for snippet expansion provided you “don’t have too many” with “too many” being unclear to me as an exact amount.

Either way, both utilities will do the job for you. As a general rule I decide between KM and Alfred based on whether the functionality of what I am doing is primarily based on a script I am writing (use Alfred) or more suited to the building blocks provided by KM (especially the macro palettes which I use extensively).

1 Like

What group is this macro in?
I recreated it and it worked when I put it in the global macro group.

1 Like

Double check that you have entered the text exactly right and haven’t left off a ‘%’ or something.
you might try the Keyboard Maestro forum. I tested it out and it works for me as you want it to.

You may have a non visible character in your trigger. Try a different trigger and see if the expansion fires.

1 Like

Worth a try, however he does have the automatic ‘5 deletes’ which matches the five visible characters, that hadn’t occured to me. @pkondo check that other dates are working in macros. At the worst there could be an issue at the source of where Keyboard Maestro draws the raw date time information. Date tokens in Keyboard Maestro are drawn from the Apple preferences date time formattings.

Wow, I really thank you all for trying to figure out my issue. I tried all the suggestions but to no avail. But then I did something super basic. I created a simple macro just to type ‘hi’ when I select the macro from the menu bar.

I then opened up a new Apple Notes doc and select the macro. Nothing happens. So something odd is happening.

I checked I was running the latest version of KM. I then just decided to shut off my laptop completely and try funning the macro from the menu bar. I did it while I was in an Apple Note and in Apple Mail. No luck.

I have attached the super simple macro here.

This is one of the main uses I get out of Keyboard Maestro and I have never had quite your problem.

Try Keyboard Maestro forum. You do have other macros that work OK? and all your permissions are correct?
Keyboard Maestro is quite sandboxed unless you give the permissions. If your other macros are working though I can’t think of anything more. You did the usual restart and so on?

Yeah John, the problem seems to be elsewhere. There is, I believe, often good reason to do it your way. I paste some snippets and put a ‘delete past keyboard’ action in to stop it cluttering my clipboard. That makes the snippet function on Keyboard Maestro pretty much as good as TE. I don’t have many, by many some mean hundreds and some have also dozens of macros. I have only about 60 macros, that is all I need but I could not manage withouth them!! I am told that large numbers of macros entail some strategic thinking to save space and RAM. It isn’t something I have to deal with. Out of interest how many macros do you have?

OK @pkondo I found this by the excellent @JMichaelTX on Keyboard Maestro Discourse.

Thanks so much for digging. I was actually in the middle of writing this but then got interrupted.

I’ve got a lot of crud on this computer but this is in prep for getting a new laptop, possibly by the end of the week. This current laptop is 7 years old and has tons of apps on it, many I don’t use.

When I get the new machine, I’m going to keep my apps minimized until I know I need them. This is actually the reason why I asked this question in the first place because I was wondering if I could get rid of Text Expander since I knew I would install KM and Alfred. This was the last snippet I was needing it for.

I’ll post back once I get my new laptop and hopefully, all this goes away.

But again, everyone here is always so generous. So thanks again for all your time and effort!


1 Like

It would be really interesting for me, us I guess, to hear how it works out, make sure you let us know. I will say that I intend to apply exactly your strategy. I am already there really. I get TE on the old rate sub as I already had it, 20 bucks a year, I wouldn’t pay more and am not sure anyway I need it. I have found that I can manage perfectly well with just Keyboard Maestro. I will say that I have a relatively small number of macros, total including snippets is unlikely to get much over 100. I rely on them totally though. Really interesting exchange, thanks Paul.