Create Bulk Macros

Hi All,
For various reasons I want to make a macro for a quite big list of commands where the key stroke action and the hotkey trigger are one in the same and the name of the macro would just be a descriptive version of the command. I have a numbers spreadsheet with 3 columns outlining it all and I;'ve also saved each one of those to a separate txt file and comma separated csv.
I got chatGPT to convert all the commands to their short form (with symbols for command and etc) and export a kmmacros file for me but when I'm import it, the actual keystroke part of each command isn;t there. I think something to do with how XML is defined or UUID is created etc. anyway -
I decided to simply make a macro that would create a new macro, name, insert action keystroke, then mimic the keystroke,.... then I stopped, and decided this doesn't feel like a good idea, hot key trigger the same as the keys stroke it's triggering?... doesn't sound good to me.

Can someone help and tell me how I can achieve this?

One way to batch create a bunch of similar macros is something like done in this macro:

However note that creating a hot key trigger requires knowing the keycode rather than the key, so that may be an issue for you. You can likely find a table mapping ASCII keys to key codes online, as the keycodes are standard for most english keyboard.

hi Peter,
I have already converted the descriptive commands, below is a picture of what I'm dealing with so you can see. Your way above is interesting and also, very involved, I was hoping it would be a bit easier than that. I made a macro to make the macros using KM itself which worked increadably well apart from when I go to specify a key stroke on the add key stroke command. Of course, I can't type something like Option+K in this circumstance, and I can paste it cause that would just end up ⌘V on every one. although, what you've given me above seems to do that.

Try again but, as Peter said, using the keycode for the the key, not the letter. You may have to adjust for your language/layout, but you'll find a good starting reference at Complete list of AppleScript key codes.

If you want to try a different way, could you post the macro that should be created by row 1 of your image? That'll give people something more definite to aim at.

I've used this table before in my macros. It's not too hard to get a macro to reference a corresponding item this data.

0 0x00 ANSI_A
1 0x01 ANSI_S
2 0x02 ANSI_D
3 0x03 ANSI_F
4 0x04 ANSI_H
5 0x05 ANSI_G
6 0x06 ANSI_Z
7 0x07 ANSI_X
8 0x08 ANSI_C
9 0x09 ANSI_V
10 0x0A ISO_Section
11 0x0B ANSI_B
12 0x0C ANSI_Q
13 0x0D ANSI_W
14 0x0E ANSI_E
15 0x0F ANSI_R
16 0x10 ANSI_Y
17 0x11 ANSI_T
18 0x12 ANSI_1
19 0x13 ANSI_2
20 0x14 ANSI_3
21 0x15 ANSI_4
22 0x16 ANSI_6
23 0x17 ANSI_5
24 0x18 ANSI_Equal
25 0x19 ANSI_9
26 0x1A ANSI_7
27 0x1B ANSI_Minus
28 0x1C ANSI_8
29 0x1D ANSI_0
30 0x1E ANSI_RightBracket
31 0x1F ANSI_O
32 0x20 ANSI_U
33 0x21 ANSI_LeftBracket
34 0x22 ANSI_I
35 0x23 ANSI_P
36 0x24 Return
37 0x25 ANSI_L
38 0x26 ANSI_J
39 0x27 ANSI_Quote
40 0x28 ANSI_K
41 0x29 ANSI_Semicolon
42 0x2A ANSI_Backslash
43 0x2B ANSI_Comma
44 0x2C ANSI_Slash
45 0x2D ANSI_N
46 0x2E ANSI_M
47 0x2F ANSI_Period
48 0x30 Tab
49 0x31 Space
50 0x32 ANSI_Grave
51 0x33 Delete
53 0x35 Escape
55 0x37 Command
56 0x38 Shift
57 0x39 CapsLock
58 0x3A Option
59 0x3B Control
60 0x3C RightShift
61 0x3D RightOption
62 0x3E RightControl
63 0x3F Function
64 0x40 F17
65 0x41 ANSI_KeypadDecimal
67 0x43 ANSI_KeypadMultiply
69 0x45 ANSI_KeypadPlus
71 0x47 ANSI_KeypadClear
72 0x48 VolumeUp
73 0x49 VolumeDown
74 0x4A Mute
75 0x4B ANSI_KeypadDivide
76 0x4C ANSI_KeypadEnter
78 0x4E ANSI_KeypadMinus
79 0x4F F18
80 0x50 F19
81 0x51 ANSI_KeypadEquals
82 0x52 ANSI_Keypad0
83 0x53 ANSI_Keypad1
84 0x54 ANSI_Keypad2
85 0x55 ANSI_Keypad3
86 0x56 ANSI_Keypad4
87 0x57 ANSI_Keypad5
88 0x58 ANSI_Keypad6
89 0x59 ANSI_Keypad7
90 0x5A F20
91 0x5B ANSI_Keypad8
92 0x5C ANSI_Keypad9
93 0x5D JIS_Yen
94 0x5E JIS_Underscore
95 0x5F JIS_KeypadComma
96 0x60 F5
97 0x61 F6
98 0x62 F7
99 0x63 F3
100 0x64 F8
101 0x65 F9
102 0x66 JIS_Eisu
103 0x67 F11
104 0x68 JIS_Kana
105 0x69 F13
106 0x6A F16
107 0x6B F14
109 0x6D F10
111 0x6F F12
113 0x71 F15
114 0x72 Help
115 0x73 Home
116 0x74 PageUp
117 0x75 ForwardDelete
118 0x76 F4
119 0x77 End
120 0x78 F2
121 0x79 PageDown
122 0x7A F1
123 0x7B LeftArrow
124 0x7C RightArrow
125 0x7D DownArrow
126 0x7E UpArrow
2 Likes

Canonical list can be found in the "Virtual keycodes" section of

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Events.h
2 Likes

An example of what the outcome I'd like is attached. Simply a name for the macro and a corresponding keystroke (no actual trigger is needed) with the later being the thing I don't know how to do. I've got the entire list saved in a few columns with the description, shortcut key, and key codes would need to be.

Chord Pads - Show:Hide Chord Pads.kmmacros (1.4 KB)

Yes, I can generate this easily enough. How do you do the next bit of converting them to macros?

You said you could already create macros via XML, except the keystroke wasn't there. Use the codes instead, converting to decimal first -- so A would be 0, B would be 11, etc. You'll also have to work out how to do the modifiers -- manually create some modified keystrokes, copy the action's XML, paste into your text editor, and you should soon spot the pattern.

I should explain, I got chatGPT to do it which most of the time is a downright waste of time but surprisingly, it did a good job on this occasion, however when importing them into KM, something weird (to me) happens. I can see the correct codes written into the code of each macro but it gets stripped out when it's read in. I also tried the key codes (I use an app called 'Key Code' highly recommend it) but then KM refuses to read it in at all. hence why I started down the make macro's for macros inside KM natively.

I tried that last advice with the text expansion and got that to work so to speak (thank you) but the app at the other end expects the commands to be keystrokes which need to more or less arrive at the same time ie ⌘K is being interpreted as ⌘ then K, which is why I really want to populate the keystroke command instead, but not sure if thats possible. I note you can also invoke commands via menu's which is cool but emulating all the commands in each menu would be to much.

The macro that creates text expansions shows you how to manipulate the XML to produce what KM expects, and how to import it. You have to change the XML to do what you want, swapping out the code for expansions for the XML for your simulated keystroke commands.

Here's one closer to what you want. This will work as-is for a US/UK standard or extended keyboard -- including function keys, arrows, the number pad...

I've left the complete list of US key codes in the first action. You should change your input file to match those and the format used in your picture -- so if you've eg Command and the Return key as the simulated keystroke it should be on your list as "Command+Return".

You'll need to export your command list as a tab-delimited file (which also allows you to use , as a keystroke) with 3 columns: macro Group, macro name, and keystroke:

Add Track	Add Track...	T
Audio	Adjust Fades to Range	A
Audio	Auto-Grid	Shift+Q
Audio	Crossfade	X
...

While there's only addition of macros, no changing or deletion, it would still be good to backup everything first!

Run the macro, select your tab-delimited list, sit back... You might want to try a small set first, just in case -- I've tested as much as I can, but I'm sure something will have slipped through.

Create Macros from text.kmmacros (16.4 KB)

Image

ah thank you very much thats amazing, I'll give it a try.

Update above -- now covers Function keys etc.

Thank you, is there anyway I can test it all within a folder on the far left or some soft or one shot tag or a second blank instance of KM etc? problem is, cuirass I've tried many things some of which are still relevant its kind of hard for me to check/ see what's new all the time.

If you change your list so that the macro Groups to use are "test_Add Track", "test_Audio", or similar it'll make new Groups with those names, making it easy for you to see what happens.