Trigger Macro by Name Using Keyword?

I have about 5,000 macros many with similar names. I extensively use palettes, nested palettes, conflict palettes, obviously many keyboard shortcuts and the trigger macro by name action.

Based on my experience with Alfred and LaunchBar, I have come to like using a search bar and a search by keyword. A keyword is short with a mnemonic component, a far cry from the descriptive name of a macro. In addition, in terms of workflow, there is something to be said in favour of keeping one's hands on the keyboard, as opposed to palettes and stretching out one's fingers to type a keyboard shortcut.

I tried adding distinctive keywords to macro names, such as $img50 for the macro that resizes the image in the clipboard by ↓ 50%, and searching for it with the trigger macro by name action, but despite the uniqueness of $img50, I end up with too many results I have to sort through before I can trigger the macro.

  1. What would be the best was to create a rapid search for macro by keyword macro ?

  2. Assuming that the answer is to use the trigger macro by name action and a keyword in the macro name, how should I structure the keyword.
    Let's say that my keyword is img50 that I would add at the end of the macro name and don't want it at the beginning of the macro name (would make reading palettes too difficult).
    Is it OK to use @img50 as a keyword and could that formulation create problems for me down the line forcing me to one day edit out all the @ symbols. Or are other symbols preferable ?

Thanks in advance for your time and help.

Could you start by reducing the number of macros? For example:

...suggests you have multiple macros that differ only in the resize amount -- you could replace them all with a single macro that prompted with a list of resize percentages.

If you want to use tags then I've just had a play and you might be able to make use of Notes. You can apply these to any action via its Settings cogwheel but, for consistency, I'd suggest starting your macros with a "Comment" action which you apply the Note to. Put your tag in the Note and you shouldn't have any problems using @ symbols etc.

You'd then "Trigger Macro by Name" with an initial search of "note":

image

Main downside is that, as noted another threads, the initial search text is selected when the prompt appears -- so you'll have to right-arrow to start adding the tag to search for.

Maybe not...

Here's a quick demo. You run the "Trigger" macro which asynchronously fires off the "Prompt" macro, waits until it is on the screen (you may have to change the image it waits for to suit your setup), then types in note: and is ready for your tag text.

Three other macros included, each with "Comment" with a Note -- @1, @2, and @3 respectively -- which you can search for and run from the prompt.

Run Macro by Tag Macros.kmmacros (46.8 KB)

Images

Trigger:


Prompt:


Macro example:

1 Like

I don't know if this is a good idea and haven't tested it, but have you ever thought of creating nested "Trigger Macro by Name" actions?

Many (10, 20?) of these actions are triggered by the same shortcut. So you get a conflict palette. For example this

image

Each of these "Trigger by Name" actions can have a different predefined prefix / keyword (and/or a macro group) that narrows down the search, but you don't have to type it every time.

Maybe if you develop this intelligently ... I have no idea if this is practical, but it works in my head :innocent:

1 Like

Thanks very much for the macro and the suggestions.

I played around with both and find it too time consuming. I think that I will go with @Frankb 's suggestion, but once again I am very grateful for your time and ideas.

Hello @Frankb,

A very good idea. A type of conflict palette. I am testing it and sees promising.

Thanks very much.

1 Like

That's really odd...

I get exactly one hit when searching for “$img50” out of some hundreds.

Remember that Trigger by Name only presents macros that are active and accessible in the context you're working in at the time.

It shouldn't make a difference – but what if you specify the name in the search string:

name:$img50

You should NOT be getting extraneous results...

Whether you add a "tag comment" or append text to the macro name, it'll take time. But with a bit of AppleScript you can select one or more macros, pop a dialog for each asking for a tag to use, then add the action as described earlier.

AppleScript
tell application "Keyboard Maestro"
	set macroList to (get selected macros)
	repeat with eachMacro in macroList
		set theTag to text returned of (display dialog "Set the tag for macro \"" & name of eachMacro & "\"" default answer "")
		set theXML to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
	<key>ActionName</key>
	<string>Holds tag Note</string>
	<key>ActionNotes</key>
	<string>" & theTag & "</string>
	<key>IsDisclosed</key>
	<false/>
	<key>MacroActionType</key>
	<string>Comment</string>
	<key>StyledText</key>
	<data>
	cnRmZAAAAAADAAAAAgAAAAcAAABUWFQucnRmAQAAAC5uAAAAKwAAAAEAAABmAAAAe1xy
	dGYxXGFuc2lcYW5zaWNwZzEyNTJcY29jb2FydGYxNDA0XGNvY29hc3VicnRmNDcwCntc
	Zm9udHRibH0Ke1xjb2xvcnRibDtccmVkMjU1XGdyZWVuMjU1XGJsdWUyNTU7fQp9AQAA
	ACMAAAABAAAABwAAAFRYVC5ydGYQAAAAd3KjV7YBAAAAAAAAAAAAAA==
	</data>
	<key>Title</key>
	<string>To hold tag Note</string>
</dict>
</plist>
"
		tell eachMacro
			set newAction to make new action with properties {xml:theXML} at beginning of actions
		end tell
	end repeat
end tell

You can run it from Script Editor/Script Debugger or, of course, from a KM macro:

Add Tags to Selected Macros.kmmacros (3.1 KB)

Image

1 Like

Hey @ronald,

See if this runs any faster then the native action.


Download: Execute Macro by Name v1.00.kmmacros (8.4 KB)

Macro-Image

Keyboard Maestro Export

Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 10.14.6
  • Keyboard Maestro v10.2

BTW – what do you have your native action set to?

image

-Chris

1 Like

I use active macros. Similar delay with your macro. Thank you.

thank you very much ! Useful in this and other situations.

@ronald Can you already roughly estimate whether the idea with the palette of different ".. by Name" macros could be practical? Maybe I will do that too if you explain how you did it. :grinning:

1 Like

@Frankb @Nige_S @ccstone

I was playing around with different apps and found the solution. An Alfred workflow which emulates the KM trigger macro by name macro and gives instantaneous results.

thank you all for your help.

iansinnott/alfred-maestro: An Alfred workflow to execute Keyboard Maestro macros.

2 Likes