How to make a predefined macro with one Keystroke action and a trigger

I very often have macros that look like this:

These macros are responsible of quickly making bindings from one key to another.

That is I make macros that always start with k: prefix followed by a custom name where the trigger is always a hotkey and it will contain only one Keystroke action.

Can I somehow make a macro that will instantly make this pre-filled structure for me. As in I press hotkey and it will make this macro:

I came up with this really slow solution:

test.kmmacros (30 KB)

Using two @ccstone macros to both make the trigger and focus on the rename area but this is really slow. I can't think of a way to quickly add a specific action (Keystroke) and do other things really fast. Ideally all under 1 second.

Thank you a lot for any help on this. This macro will save me a lot of time if it would work.

Once again, @ccstone's AppleScript and KM8's new menu actions come to the rescue (be sure to edit the macro group name at the top of the script, on the "set macroGroupName to "Test Group" line, to the one you want for your own macros):

New Predefined Macro.kmmacros (6.2 KB)

I started with the script Chris shared here, added a line to ensure KM would be made the frontmost app if it wasn't already, added new entries for the newly created macro's trigger and actions using the excellent Script Debugger to grab the XML for each, and finished it off with KM8's own native "Edit Name" menu item. It run at an average of about 0.64 seconds on my system and seems to work just as you specified, but let me know if you run into any issues with it.

1 Like

This is really awesome. Thank you @gglick

This doesn’t quite work for me for one reason. My macro groups change all the time. Since this macro can be used in Safari group or Keyboard Maestro group. Can it somehow figure out what group I am currently in and use that?

You're welcome, @nikivi! And yes, it can figure that out easily. Here's a modified version that does that:

New Predefined Macro 1.0.1.kmmacros (6.2 KB)

The only difference is that I replaced the

set macroGroupName to "Test Group"

line with

	tell application "Keyboard Maestro"
		set macroGroupName to name of item 1 of (get selected macro groups)
	end tell
1 Like

This works perfectly. Thank you so much @gglick

This will save me a lot of time. Only thing I aded was cmd + right arrow keystroke as the rename highlights the macro and I want to immediately start typing the name. But other than that it is perfect and is super fast. :purple_heart:

1 Like