Auto Insert Favorite Tokens in Keyboard Maestro

:grin:

AAA - Keyboard Maestro Macros (v11.0.3)

AAA - Keyboard Maestro Macros.kmmacros (515 KB)

It's fun to see what some of your more often used Tokens are. I played around with all of them.

@Airy

I'd love to hear any comments about any of these if you care to share what you use them so often for. In particular the return and line feed. Is it better to use a token than just paste them in?

https://wiki.keyboardmaestro.com/token/Return?s[]=%25return%25

https://wiki.keyboardmaestro.com/token/LineFeed?s[]=%25linefeed%25

image

2 Likes

Instead of having to remember all those shortcuts I just use these:

βŒƒβŒ˜A - insert an Action (in a macro)

βŒƒβŒ˜T - insert a Token (in a field)

βŒƒβŒ˜V - insert a Variable (in a field)

βŒƒβŒ˜F - insert a Function (in a field)

βŒƒβŒ˜W - insert an ICU Date (in a field)

Each of these brings up a spotlight-like search as appropriate allowing easy search/selection of action/token/variable/function/date respectively.

BTW - these are baked into KM - no extra macro/hot keys needed.

5 Likes

I do love those and use the first one all the time and Token and Variable often. I need to learn more about function and I usually search for the ICU one to get the format I want but use macros that use those daily. Thanks for posting.

I think I am going to make a searchable list of my favorites. Somewhat related is @DanThomas Tutorial: Keyboard Maestro Customized Actions and Named Clipboards

I wish they were always stuck; it seems like they get lost on occasion between computers with a Dropbox sync.

βŒƒβŒ˜A - insert an Action (in a macro)

βŒƒβŒ˜T - insert a Token (in a field)

βŒƒβŒ˜V - insert a Variable (in a field)

βŒƒβŒ˜F - insert a Function (in a field)

βŒƒβŒ˜W - insert an ICU Date (in a field)

I'd love to see the macro that created these.

2 Likes

If you mean the keycaps, they're just markdown formatting like this, for example:

<kbd>X</kbd> gives X

You can of course create macros to make typing these easier...but I use Typinator myself.

Also @_jims has given us a great post here

2 Likes

When creating posts, I use this macro to do transformation like that: Augment or Transform Text

I also use it within the Keyboard Maestro editor frequently to do transformations like this

local_Text β†’ %Variable%local_Text%


On the topics of tokens, you might also find this macro useful: Insert Token

2 Likes

Yes, %Return% is very handy, because in my macros I want to be able to see if there is a return after the text. (And I also want other people to see a Return is there if I'm sharing my macro.) For example,

image

That's much easier to understand than:

image

You can't see the trailing Return in there! So "%Return%" is very useful.

1 Like

That is very smart and makes sense, thank you for explaining I think I will begin to implment that as well. There have been several times I have wanted to see that but it hasn't been clear. You also have in group B LineFeed. When would you use that over using the return. I know that is more common on macOS and Linux but not sure if there is any programing or practical reason.

Yes, that is very helpful thanks for sharing.

Thank you for making this you had me down a rabit hole for quite sometime between that link and the following link both by @_jims. Very helpful links and macros.

1 Like

I'm not sure. I just searched for that token in my current set of 1000 macros, and didn't find any. (Every time I buy a new Mac, I don't import any macros, I just start all over from scratch, even if it means rewriting some big macros.)

When I was looking at the complete set of tokens, part of my selection criteria was making choices that were useful, but another part was making choices that used as much of the alphabet as possible. There weren't a lot of choices for the letter "L", so Linefeed managed to squeak in there, barely. You can delete it if you want to.

Haha, that's cool you're a very honest guy, thanks for being transparent.

That is wild, I think I would lose my mind if I did that. Do you do that just to keep things fresh, only keep what you need, and to hopefully improve upon any old macros?

The journey is the destination. Writing macros and making them work is what I enjoy, even more than using the macros that I write.

1 Like

That is very cool it shows very much in all the help you give so many. I am very grateful for people like you. It is a lot of fun to make things work and overcome a good puzzle challenge.

2 Likes

%LineFeed% is the modern Mac/*nix end-of-line character -- often written as \n. %Return% is the old-style Mac Classic EOL character, \r. (Windows is both together -- %Return%%LineFeed% or \r\n.)

IMO, best practice is to use %LineFeed% because that's the "modern way" -- and also makes life easier if you use the result in a *nix utility, as you can see here:

LF and CR Demo.kmmacros (5.6 KB)

Images

...and remember to use \R in your regular expressions, to catch all three variants.

But much of the time any "conversion" is handled for you -- KM "lines in collection" is EOL-agnostic, so is AppleScript's "paragraphs of", receiving apps work with the System Clipboard to paste "sensible" results, etc.

2 Likes

Thank you for the macro, that was very helpful. I didn't know you could sort things that way. I made a macro to sort the selected text using that and paste it back, though that of course wasn't really what you were demontrating that was helpful.

Thanks for the reminder and great tip stay away from \r.

This is not a good way to do a simple line sort! KM's "Filter" action:

image

...is also line-ending agnostic.

In general, avoid shell/AppleScript actions unless you have a need -- a function not available in KM or a processing chain that would take many KM actions to do, for example. KM actions are blisteringly fast for text operations, and you have to replace a lot of KM text actions with a single "Execute a Shell Script" action to overcome the time cost of instantiating the shell.

Example time! On my machine I can do 9 Filter sorts in the time it takes to do 1 shell sort:

Filter vs Shell Sort.kmmacros (7.1 KB)

Image

1 Like

Good to know. I did notice that I had to delete a lot of past clipboards with what I was trying to do with the Shell sort and never quite got back to where I started. I figured Keyboard Maestro had something in it but I was kind of excited about the Shell sort so I didn't even search the Wiki.

That's great to know, Keyboard Maestro is much faster on my M4 as well. Though the Shell got a little faster each time I ran it. Perhaps it was loading into RAM or something but it never beat Keyboard Maestro.
image

So, assuming you used the same repeat values as me, Filter is ~4 times faster for you than the Execute a Shell Script action.

That plays along with my untested theory -- the faster the processor, the fewer simple KM actions the Execute a Shell Script action need replace to become optimal. That's because KM actions execute at a maximum rate of 1,000 actions per second, regardless of processor speed, but the speed of shell instantiation and that of the processes executing within that instance isn't similarly restricted.

But we're talking milliseconds here, so not really something to worry about in practical use. Go with what works and, importantly, with what makes sense to you.

Thanks for that link to the forum post I wasn't aware of that. Yes Keyboard Maestro was over 4x faster. I set them both to 100 times and this is the result on an M4.

image