MACRO: Edit a Recently Executed Macro, v1.0

PURPOSE

This macro opens the most recently executed macro in the Keyboard Maestro Editor.

Alternatively, if triggered using the secondary hot key, the one that includes Shift (⇧), the 14 most recently executed macros are listed in a Prompt With List. (The default value is 14 because this number of macros vertically fills the Prompt With List menu; however, the default value can be optionally changed using the local_SecondaryTrigger_NoEntries variable.)

When the Prompt With List is displayed, the selected macro is opened in the Keyboard Maestro editor. Alternatively, if Shift (⇧) is held down when the macro is selected, the macro is executed.


EXECUTING THIS MACRO FROM ANOTHER MACRO AND/OR BY USING APPLESCRIPT

If this macro is run from another macro using the Execute a Macro action (or via AppleScript), and With Parameter (WP) is specified, the macro runs as follows:

WP Behavior
null run in normal mode, i.e., the most recently executed macro is opened
>1 the integer number of macros are included in the Prompt With List. Again, the selected macro can be edited or executed.

SETTINGS

local_SecondaryTrigger_NoEntries : refer to the PURPOSE section above.

local_RegexPatterns_MacrosToExclude : can be optionally configured to exclude macros. The value can be one or more text lines, each a regular expression pattern. For example:

^_
[Uu]ntitled

macros that begin with underscore (_) or include Untitled or untitled are excluded. Note that

^%ExecutingThisMacro%$
^%ExecutingMacro%$

are automatically excluded.


ACKNOWLEDGEMENTS

This macro uses JXA shared by @ComplexPoint (N most recently run macros (Name, UUID, Stats)) that extracts data from Keyboard Maestro Macro Stats.plist. Minor modifications were made to provide compatibility with Keyboard Maestro v10+.


TESTED WITH

β€’ Keyboard Maestro 11.0.3
β€’ Sonoma 14.6.1 (23G93)/MacBookPro18,2
β€’ Sonoma 14.6.1 (23G93)/VariableMacBookPro16,1
β€’ Mojave 10.14.16/Macmini6,2
β€’ High Sierra 10.13.6/iMac11,1445


VERSION HISTORY

1.0 - initial version


EXAMPLE PROMPT WITH LIST

When using the secondary trigger (or called with a With Parameter), a Prompt With List similar to the following will be displayed.


Edit a Recently Executed Macro Macros.kmmacros (44.8 KB)

4 Likes

Hello Jim :wave:

First of all - nice Macro… but I got an error from either the JXA Action that contains the code from Rob (Group: N most recently run Macros…) or either the other one (Group: Generate the PWL Entries).

Details below.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MACRO ERROR OCCURRED  on  2024-09-05 07:31:50
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This info was pulled from the KM Engine Log for the
Last Macro error that occurred.

MACRO:
------------------------------------------------------------------------------------------------------------
Edit a Recently Executed Macro
------------------------------------------------------------------------------------------------------------

Action Type:	Execute a JavaScript For Automation
Action Name:	Execute JavaScript For Automation

ACTION ERROR:	 script error: text-script: execution error: Error: Error: Objekt kann nicht gefunden werden. (-1728). 

KM Engine Log:	
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Execute a JavaScript For Automation failed with script error: text-script: execution error: Error: Error: Objekt kann nicht gefunden werden. (-1728). Macro β€œEdit a Recently Executed Macro” cancelled (while executing Execute JavaScript For Automation
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

Log File:  ~/Library/Logs/Keyboard Maestro/Engine.log

I am sorry that I only can provide this kind of information to you … Haven’t had the time to update Engine Log Tool yet.

Hoping the information is helpful anyway…

Edit: such a case is the reason why my Scropt Actions are always named … so that I am able to identify them very easy if a script goes wrong. Please consider doing this in the future. It saves a lot of time when multiple scripts are used.

Greetings from Germany :de:

Tobias

Stunning… Thank you

Could I show the triggers?

The reason is sometimes something stops working, I got to the recently executed macros to see if I've accidentally assigned a hotkey to something

1 Like

Hi, @Nr.5-need_input. I'm sorry that you have encountered a problem with this macro.

I suspect that you are not using Keyboard Maestro v11+. If that's the case, my ability to help is limited as I've upgraded my three macs.

As I stated elsewhere, I'm generally not targeting Keyboard Maestro pre-v11, but this macro was an exception because I had seen @adamg's request for a macro that would be v10.2 compatible.

As I was creating Edit a Recently Executed Macro, @adamg and I exchanged PM's. An earlier draft of this macro was working for @adamg's v10.2, but since that draft, I did make a few changes. My assumption was that none of the changes would be incompatible with v10.2.

If @adamg or some other v10.2 user downloads, tests, and reports back, we'll at least know if this is related to the Keyboard Maestro version or something else unique to your system.


In the meantime, @Nr.5-need_input, to troubleshoot, I suggest you insert a Display Text action after each JXA action and display local_MreJson and local_MrePwlList, respectively.

Hi, @olifrost. I'm glad you like the macro. Thanks for the feedback.

Theoretically, yes, but not without much more complexity that I don't plan to add to this macro. Here's why: Edit a Recently Executed Macro uses data from the Keyboard Maestro Macro Stats.plist file, thanks to the JXA code shared by @ComplexPoint. However, the plist does not contain trigger information.

When you suspect a mistaken trigger, you have a few troubleshooting options:

  • Create a Smart Group and and specify something like this: used:2m. (On a related note, you might find this macro useful: Search All Macros)

  • Search the Engine.log (Help > Open Logs Folder). For that task, you might find this macro useful: Engine.log Tool

Thanks! I do have a smart group like that, just looking to make a macro to get there. I’ll try your other two methods.

1 Like