Iterating through macros?


Is it possible to loop/iterate through macros, and perform actions on them?

There are 2 ways to get a list of macros that I’ve found by searching this forum.

The first uses AppleScript and the KM Editor application to obtain the macro list.

The second uses JavaScript to extract the information from a KM plist file.

Depending on what “actions” you want perform will dictate whether either of these approaches is relevant.

I'd say this is definitely a job for AppleScript:

tell application "Keyboard Maestro"
  --- Get the Currently Selected Macro ---
  set {oMacro} to selected macros
  --- Get All Actions in Selected macro ---
  set actionList to actions in oMacro
  --- Loop Through All Actions ---
  repeat with oAction in actionList
    tell oAction
      set actionXML to its xml
      set actionName to its name
    end tell -- oAction
  end repeat
end tell

I recommend that you use Script Debugger 7+, which has both a paid version and a free lite version. Even the lite version is much better than the Apple Script Editor, which you can also use.

In SD7+, you can view the KM Action objects and properties using the SD Dictionary: