Smart Group Syntax for Keyboard Shortcuts: how to include Macro Group hot keys

I can't find a way around this either.

I think so too.

I think,:crossed_fingers:, I have an AppleScript for that.

So it would seem you're now back to the display issue.

A native Smart group display seems out of reach.

A Custom HTML Prompt might be an alternative.

To get you started on how to use the decoding results of the decoding AppleScript, I've uploaded a macro to demo plugging the results into a Custom HTML Prompt.

USAGE:

  1. Enable the macro group and macro
  2. Run the macro.
  3. A list with macro groups and hot keys and enabled state will appear
  4. To edit to the macro group in the KM Editor, click its name
Image

AppleScript Summary
  1. Identify the groups with hot key assignments with the previous AppleScript.

  2. Extract the hot key information from the value of the "group xml" property (deserialized) of the macro groups.

  3. Convert the number values of KeyCode and Modifiers keys to familiar characters and symbols. eg. Modifiers:512 and KeyCode:64 ==> ⌘F7

  4. Format the conversion as preformatted html eg."<a href= "keyboardmaestro://m=" & groupUID & "">" & groupName & " " & modifiersSymbols & keyCodeCharacters

AppleScript
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
property author : "@CRLF"
--┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
--┃ Outputs information on Macro Groups with hot keys
--┃ in preformatted html. 
--┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
tell application id "com.stairways.keyboardmaestro.editor"
	set groupXMLs to group xml of macro groups whose activation xml contains "KeyCode" and activation xml does not contain "32767"
	set groupDicts to (current application's NSMutableArray's arrayWithArray:groupXMLs)'s valueForKeyPath:"propertyList"
end tell
(*
--To browse all possible info keys, uncomment:
if groupDicts's |count|() > 0 then
	return ((((groupDicts's objectAtIndex:0)'s allKeys())'s sortedArrayUsingSelector:"compare:")'s componentsJoinedByString:linefeed)
end if
*)
set keyCodeDict to keyCodeLookUps()
repeat with aGroup in groupDicts
	set temporaryDict to (aGroup's dictionaryWithValuesForKeys:{"Name", "KeyCode", "Modifiers", "UID"})'s mutableCopy()
	set {aKeyCode, theModifiers} to (temporaryDict's objectsForKeys:{"KeyCode", "Modifiers"} notFoundMarker:"not found")
	set keyCodeCharacters to (keyCodeDict's objectForKey:(aKeyCode)) as text
	set modifiersSymbols to (modifiersToSymbols((theModifiers) as text))
	set modifiersSymbols to reorderModifiersKMStyle(modifiersSymbols)
	(aGroup's addEntriesFromDictionary:(current application's NSDictionary's dictionaryWithObjects:{keyCodeCharacters, modifiersSymbols} forKeys:{"KeyCodeCharacters", "ModifiersSymbols"}))
end repeat

set hrefLines to {}


repeat with aGroup in groupDicts
	
	(((aGroup's allKeys())'s sortedArrayUsingSelector:"compare:")'s componentsJoinedByString:linefeed)
	set enabledStatus to ""
	set {keyCodeCharacters, modifiersSymbols, groupName, groupUID, enabled} to (aGroup's objectsForKeys:{"KeyCodeCharacters", "ModifiersSymbols", "Name", "UID", "IsActive"} notFoundMarker:true) as list
	if not enabled then set enabledStatus to " (disabled)"
	set href to "<a href= \"keyboardmaestro://m=" & groupUID & "\">" & groupName & "</a> " & modifiersSymbols & keyCodeCharacters & enabledStatus
	set end of hrefLines to href
end repeat
set beginning of hrefLines to "<pre>"
set end of hrefLines to "</pre>"
set {TID, text item delimiters} to {text item delimiters, linefeed}
return (hrefLines as text)
--===============HANDLERS=================
on keyCodeLookUps()
	set allObjects to {"A", "S", "D", "F", "H", "G", "Z", "X", "C", "V", "B", "Q", "W", "E", "R", "Y", "T", "1", "2", "3", "4", "6", "5", "=", "9", "7", "-", "8", "0", "]", "O", "U", "[", "I", "P", "Return", "L", "J", "'", "K", ";", "\\", ",", "/", "N", "M", ".", "Tab", "Space", "`", "Delete", "Enter", "Escape", "RightCommand", "Command", "Shift", "CapsLock", "Option", "Control", "RightShift", "RightOption", "RightControl", "Function", "F17", "Key Pad .", "Key Pad *", "Key Pad +", "Clear", "Key Pad /", "Enter", "Key Pad -", "F18", "F19", "Key Pad =", "Key Pad 0", "Key Pad 1", "Key Pad 2", "Key Pad 3", "Key Pad 4", "Key Pad 5", "Key Pad 6", "Key Pad 7", "F20", "Key Pad 8", "Key Pad 9", "F5", "F6", "F7", "F3", "F8", "F9", "F11", "F13", "F16", "F14", "F10", "F12", "F15", "Help", "Home", "PageUp", "Forward Delete", "F4", "End", "F2", "Page Down", "F1", "LeftArrow", "RightArrow", "DownArrow", "UpArrow"}
	set allKeys to {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 67, 69, 71, 75, 76, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 96, 97, 98, 99, 100, 101, 103, 105, 106, 107, 109, 111, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126}
	return current application's NSDictionary's dictionaryWithObjects:allObjects forKeys:allKeys
end keyCodeLookUps

on modifiersToSymbols(bitmask)
	set modifierMap to {¬
		{"⌘", 256}, ¬
		{"⇧", 512}, ¬
		{"⌥", 2048}, ¬
		{"⌃", 4096}, ¬
		{"⇪", 1024}}
	set detected to {}
	repeat with i from 1 to count of modifierMap
		set {symbol, value} to item i of modifierMap
		if (bitmask div value) mod 2 is 1 then
			set end of detected to symbol
		end if
	end repeat
	return detected
end modifiersToSymbols

on reorderModifiersKMStyle(symbolString)
	-- KM-style display order
	set kmOrder to {"⌃", "⌥", "⇧", "⌘", "⇪", "Fn"}
	set reordered to {}
	repeat with s in kmOrder
		if symbolString contains (s as string) then set end of reordered to contents of s
	end repeat
	return reordered as text
end reorderModifiersKMStyle

Display Macro Group Hot Keys Usage.kmmacros (6.9 KB)

2 Likes