As of v8.0, the Keyboard Maestro editor is fully OSA (Open Scripting Architecture) compatible. This means you can edit your Keyboard Maestro macros from AppleScript in a variety of powerful ways.
The Keyboard Maestro Scripting Definition (sdef) describes all the support, and you can open in in the Script Editor to see more details. Here are some examples of what you can do:
tell app "Keyboard Maestro" properties of group "Enabled" properties of smart group "Enabled" make new smart group with properties {name:"Enabled", search strings:{"enabled:yes"}} set search strings of smart group "Disabled" to {"enabled:no"} set enable of macro group "Turn Off" to false set name of macro 1 to "Great!" tell macro group "New Stuff" to make new macro set color of action 1 of macro "Bright" to "red" select action 1 through 3 of action 2 of macro "Working" set selection to global macro group move first action of macro "Source Macro" to end of actions of macro "Dest Macro" move macro "Macro33" to macro group "Test4" move (every macro of macro group "Test4" whose name starts with "Macro3") to macro group "Test3" move macro 2 of macro group "Test3" to macro group "Test4" delete second action of macro "Target Macro" duplicate every macro group whose name starts with "Test" set m to duplicate action 1 of macro "Macro33" to after action 2 of macro "Macro32" duplicate (selected macros) to macro group "Test4" end tell
Here is a full example that creates a macro group called “Multiple Clipboards” and then creates 9 macros with hot Control-C and action to copy the clipboard to a named clipboard with name “Clipboard N” (where N is 1-9) and another set of 9 macros with hot key Control-V and action to paste from the named clipboard “Clipboard N”
tell application id "com.stairways.keyboardmaestro.editor" set mg to make new macro group with properties {name:"Multiple Clipboards"} tell mg repeat with i from 1 to 9 set m to make new macro with properties {name:"Copy " & i} tell m make new trigger with properties {xml:"<dict> <key>FireType</key> <string>Pressed</string> <key>KeyCode</key> <integer>8</integer> <key>MacroTriggerType</key> <string>HotKey</string> <key>Modifiers</key> <integer>4096</integer> </dict>"} make new action with properties {xml:"<dict> <key>Action</key> <string>Copy</string> <key>MacroActionType</key> <string>ClipboardSwitcherMacroAction</string> <key>RedundandDisplayName</key> <string>Clipboard " & i & "</string> </dict>"} end tell set m to make new macro with properties {name:"Paste " & i} tell m make new trigger with properties {xml:"<dict> <key>FireType</key> <string>Pressed</string> <key>KeyCode</key> <integer>9</integer> <key>MacroTriggerType</key> <string>HotKey</string> <key>Modifiers</key> <integer>4096</integer> </dict>"} make new action with properties {xml:"<dict> <key>Action</key> <string>Paste</string> <key>MacroActionType</key> <string>ClipboardSwitcherMacroAction</string> <key>RedundandDisplayName</key> <string>Clipboard " & i & "</string> </dict>"} end tell end repeat end tell end tell