thank you again for your time and expertise.
1- below is the script which I attempted to modify the original macro as per your instructions, and yields an error message. I hope that I did not bungle the script editing.
KM Engine log
Execute an AppleScript failed with script error: text-script:2316:2328: execution error: The variable groupHKDicts is not defined. (-2753).
2- the macro downloaded from your latest post gives erroneous results. In the (see ScreenShot below) item (1) (F7) is from your initial macro and is correct and item (2) from your latest post is incorrect (F3)
3- minor issue: the HTML window is very small. No problem. I just stretch it manually.. It was much better with your very very initial macro which I can no longer find. I tried to "modify engine window" both before and after the HTML action to no avail. I can't find where you define the window size.
thank you again. If you have any urge to throw your Mac out the window, please stop working on this project !
0use 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 modifiersDesc to current application's NSSortDescriptor's sortDescriptorWithKey:"Modifiers" ascending:true selector:"compare:"
set keyCodeDesc to current application's NSSortDescriptor's sortDescriptorWithKey:"KeyCode" ascending:true selector:"compare:"
set nameDesc to current application's NSSortDescriptor's sortDescriptorWithKey:"Name" ascending:true selector:"localizedStandardCompare:"
set groupDicts to groupDicts's sortedArrayUsingDescriptors:{modifiersDesc, keyCodeDesc, nameDesc}
set hrefLines to {}
set keyDesc to current application's NSSortDescriptor's sortDescriptorWithKey:"key" ascending:false selector:"compare:"
set nameDesc to current application's NSSortDescriptor's sortDescriptorWithKey:"name" ascending:true selector:"compare:"
set groupHKDicts to groupHKDicts's sortedArrayUsingDescriptors:{keyDesc, nameDesc}
set tempDicts to groupHKDicts's dictionaryWithValuesForKeys:{"key", "name", "uid"}
set {thekeys, theNames, uids} to tempDicts's objectsForKeys:{"key", "name", "uid"} notFoundMarker:"not found"
repeat with i from 1 to count of theNames
set {hotKey, groupName, groupUID} to {item i of thekeys, item i of theNames, item i of uids}
set href to "<a href= \"keyboardmaestro://m=" & groupUID & "\">" & groupName & "</a> " & hotKey
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