KM Search Syntax: gl: h:⇧⌥ ⌘. - how do I specify that the macro has to be active, and can belong to any group and Fn question

gl: h:⇧⌥ ⌘ finds macros that are globally active with the trigger shift-opt-cmd

How do I specify that the macro can belong to any group (not just the selected macro group)?

If I click on KM→ Edit → Find, the search is limited to the currently selected macro group, not all macros as I want.

I would like to have 2 versions: one displaying all active macros and the other all enabled macros.

I have a second question: what is the search syntax to find all macros trigger by Fn keys (F1 to F19)

thanks in advance for your time and help

Searches are within a Group or Smart Group -- select the "All Macros" Smart Group to search everything.

I'm not sure you can exactly do that. You can find all globally active macro, but that wouldn't include macros scoped to the KM Editor. But gl:, when the "All Macros" Smart Group is selected, is probably near enough.

Again with the "All Macros" Smart Group selected (and bearing in mind the above), e: for all enabled macros or e: -gl: for those that are enabled but not globally active.

Rather than searching "All Macros", consider setting up Smart Groups to do what you want. For example:

image

I don't think you can, I think "Search" is AND, with no wildcards (would love to be proven wrong!). Again, a Smart Group helps:

image

...and you could select that Smart Group then use the "Search" box as normal to narrow things further.

1 Like

It's crystal clear. Thanks very much for taking the time to write such a comprehensive reply.

Sorry for a follow-up question: I created a KM Go To Palette which allows me to quickly navigate between groups using each group's UUID and a simply AppleScript. It is very useful and I use it a lot.

Do I understand correctly that this is still not possible with smart groups (no copy UUID option in the smart group context menu) which is quite inconvenient.

Select the Smart Group in the Editor, then run the following AppleScript in Script Editor:

tell application "Keyboard Maestro"
	return selection
end tell

The result will be of the form

{smart group id "4FCAA4C2-4460-4961-9BB7-269E5048CFB7" of application "Keyboard Maestro"}

Copy the smart group id "..." bit and paste into another script so you get

tell application "Keyboard Maestro"
	select smart group id "4FCAA4C2-4460-4961-9BB7-269E5048CFB7"
end tell

Select a different Group in KM, run the above, and your Smart Group should be selected.

Depending on how you've done your Palette and its macros, the above may be enough. If you've got clever and each macro on the Palette simply passes a UUID to a shared sub-routine there may be a bit more work to do because of the different classes...

2 Likes

WOW !!! incredible ! fantastic !! obviously works perfectly. Thanks so much !!

Hi,

once again, your solution for go to a smart group is a gem.

a recurrent issue with KM searches is for example

  • looking specifically for F1
  • ending up with all F1* as illustrated

It would be too tedious to type F1 -F10 -F11 etc

Do you have a workaround ?

thank you

Tedious typing? Sounds like a job for KM and the "Insert Text" action!

And you don't have to type it that often unless, for some reason, you are continually making, using, then deleting the Smart Group. In which case:

tell application "Keyboard Maestro"
	set theGroup to (make new smart group with properties {name:"AS-created Fn Match", search strings:{"h:F1 -h:F11 -h:F12 -h:F13 -h:F14 -h:F15 -h:F16 -h:F17 -h:F18 -h:F19"}})
	select theGroup
end tell

If you want to make other Smart Groups on the fly like this, the easiest way to get the search strings entry is to make the Group how you want it, select it, then run:

tell application "Keyboard Maestro"
	return search strings of (item 1 of (get selection))
end tell
1 Like

Thank you very much for the scripts. I apologize for poorly thought through and worded question.
In fact, it was an academic question about searches, not a question about that specific Fn search.
if I write h:F1, I end up with F1, F11, F12 etc. How would I write my search so that I end up with F1 only.
Sorry again for a very poorly phrased question

thank you very much for the scripts. I will try them out.

Almost as you did it in your question, and like I did in my script:

h:F1 -h:F11 -h:F12 -h:F13 -h:F14 -h:F15 -h:F16 -h:F17 -h:F18 -h:F19

Literally "find all the macros with hotkey triggers that contain F1 but not those with hotkey triggers that contain F11 and not those with hotkey triggers that contain F12...".

1 Like

in fact, that it what I meant when I referred to tedious to write in my poorly worded question. For fun, I am listening to the course on Shakespeare in "The Great Courses" (repertory of university lectures). Hopefully, I will be able to express myself more clearly, using better language and ... metaphors.

1 Like

I just discovered another issue - how could I include macro GROUP triggers (hotkeys that trigger macro groups - as in shows a palette) in the search for hotkeys.

My Smart Group search for F19 yielded nothing, but I can't use F19 which is already taken, as shown below.

You're searching macros, not Groups.

If you want to search Group attributes I think you are going to have to step out and use AS. This is working for me, and I've included a list of Function key keycodes -- just change the integer value of the whose clause to suit (this searches for F19):

(* Function key keycodes
F1	122
F2	120
F3	99
F4	118
F5	96
F6	97
F7	98
F8	100
F9	101
F10	109
F11	103
F12	111
F13	105
F14	107
F15	113
F16	106
F17	64
F18	79
F19	80
F20	90
*)

tell application "Keyboard Maestro"
	set groupList to every macro group whose activation xml contains "	<key>KeyCode</key>
	<integer>80</integer>
"
	if (count of groupList) = 0 then
		display dialog "Function key not used as Group trigger"
	else
		set selection to groupList
	end if
end tell
2 Likes

works perfectly.
And what about if I want to list all macro GROUP hotkeys and corresponding macro group ?
As if I created a smart group listing all macro groups and their hotkeys ?
I ask this because I think that it's a common problem. The number of times where I have been searching macro groups one by one to remember their hotkeys !
thank you !

I think that the best thing you could do would be to start documenting your hot key usage. A simple spreadsheet would go a long way, and would let you easily include application availability, window conditions, what the activation type is, and so on. Much more useful than a list of hot keys that may, or may not, be available in a particular context.

<Placeholder>
It turns out that firing gethotkeys at the Engine gets you a list of currently available hot key triggered items for the current context. The list includes Groups! The Group entries have a particular format:

				<key>name</key>
				<string>Palette Test [Macro Group]</string>
				<key>sort</key>
				<string>)Palette Test [Macro Group]</string>

...the name appended with <space>[Macro Group] and an odd prepend on the sort string. That may be enough to separate and process Groups -- if I can work out how to parse the XML.
</Placeholder>

Otherwise, to generate a list of all Group hot keys you are going to have to get every macro that has a KeyCode but that is not 32767. Extract the KeyCode and Modifiers values. Then translate those into something readable. Hmmm...

Try this. It should give you a "Display dialog" showing tab-separated Group UUID, name, hot key, and modifiers:

List Group Hot Keys.kmmacros (16.7 KB)

Image

I've only a few hot key activated Groups, but it seems to work...

1 Like

Great ! Works perfectly, with the UUID as a bonus. Thanks very much for your help and patience.

Turned out to not be as difficult as I thought -- probably because I've taken some shortcuts which may, or may not, limit its reliability :wink: But this should get you a list of Macro Groups and their hot keys, limited to only those available in the current context:

Active Palette Hotkeys.kmmacros (19.8 KB)

Image

1 Like

It's exactly what I wanted. I had edited the results of the previous macro to arrive at this. So all is great ... thanks to you !