How to create a shortcut that Edits the Last Used Macro?

That's great information! But I suppose that means the Editor has access to some Engine data source besides the Engine log file, because the Engine log file doesn't provide a UUID for the last macro. Any idea what that might be?

Sounds accurate, but awareness the Engine Log file exists is basically the extent of my knowledge about it.

That is correct.

Well, it could ask the engine directly, of course. But you could also find this out in the "Keyboard Maestro Macro Stats.plist" file in the Application Support folder. That's what I use here, although I haven't released this yet:

 
The "Last Used" column is actually "days since last used", but internally I store the actual last used date/time.

2 Likes

Some subtleties here, perhaps:

  1. The last triggered macro is presumably always this one, so we may often be looking for the penultimate trigger event
  2. The entry to the Keyboard Maestro Macro Stats.plist file is presumably written when a macro concludes (rather than starts), so if two are running we may need to distinguish between most recently started and the most recently finished. (which may be the same).

For a macro which lists the N most recent trigger events recorded in Keyboard Maestro Macro Stats.plist, with the names and UUIDs of the triggered macros, see:

1 Like

A draft:

Edit MRU KM Macro (draft).kmmacros (10 KB)

Thanks for guidance @ComplexPoint!

Running the Macro you shared resulted in this error:

Execute a JavaScript For Automation failed with script error: text-script:0:15: script error: Error on line 1: SyntaxError: Return statements are only valid inside functions. (-2700)

Any thoughts on how to fix? Thanks

In the small chevron to the left of of the text box of the Execute JavaScript action, you may need to reset the value back to Modern Syntax

Perhaps that setting has accidentally become unchecked ?

Screenshot 2024-08-28 at 5.26.16 PM


Unless you are using a pre-11 version of Keyboard Maestro ?

On a related note, I cobbled together a macro that presents a list of the ten most recently executed macros and, if one is selected, Keyboard Maestro opens and the macro is selected for editing.

The list is presented using a slightly modified version of @DanThomas's macro: Get Recently Run Macros with Last Executed Time

Download: Edit a Recently Executed Macro.kmmacros (23 KB)

Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 14.5 (23F79)
  • Keyboard Maestro v11.0.3

EDIT: Now that I see @ComplexPoint's N most recently run macros (Name, UUID, Stats), I could create a more robust version if the Prompt With List entries were in the following form:

MacroUUID__MacroName**

**To be bulletproof, my improved version should be able to accommodate macro names that include consecutive underscores.


2024-09-04 EDIT: I've shared an improved version of the macro: Edit a Recently Executed Macro

1 Like

Ohh - yea I'm on Version 10.2 :slightly_frowning_face:

Thanks though for the tip…I'll keep poking around to see if I can get it to work

Ohh - yea I'm on Version 10.2 :slightly_frowning_face:

The first thing to try then is just to remove the opening return keyword from the code in the Execute JavaScript for Automation action.


i.e. leaving, in the first line, just:

(() => {

( Ver 11 is a good upgrade )

1 Like

Thanks for your patience on this!

I did the suggested change and the new error is:

Execute a JavaScript For Automation failed with script error: text-script: execution error: Error: ReferenceError: Can't find variable: kmvar (-2700)

Thanks! This macro is a great workaround in the meantime…

Would ideally love to skip the prompt and just open the last triggered macro. I'm fiddling with this now, if I'm able to get it to work I'll post the macro here so future folks can find it, thanks again!

Hi, @adamg. I've shared a macro that does just that: Edit a Recently Executed Macro

1 Like

This is amazing - thanks so much @_jims !!

On my machine (I'm also on Keyboard Maestro v10.2) I needed to add a pause at the beginning…otherwise this macro is seamless!

Also thanks to everyone who helped contribute to this thread!

Sidebar: This is hands-down the best forum on internet! :rocket:

1 Like

Hi, @adamg. When you say...

...are you referring to the macro I contributed in this thread or the new one I shared in the macro group?

If the latter, I have no idea why you would need to add a pause. If you are referring to the former, I suggest you download and use the latter.

Hey Jim :wave:

The latter one?!

We two already talked about the latter one and KM 10 - do you remember?! You also mentioned in our conversation that Adam (@adamg ) is also using KM 10 like I do …

By the way I haven’t had the time to look after my issue with your macro yet …

Greetings from Germany :de:

Tobias

I remember discussing this with you, but I wanted to confirm @adamg's observation.

As I shared with you, I cannot think of any reason why the latter would stumble on v10.2.

Hi @_jims - it's the latter I'm referring to.

Btw, that wasn't a complaint! I love the macro, it works for me just fine (after I added the pause at the beginning)...

So please don't view my comment as a negative, my problem is 100% solved thanks to you!

Hum, that's interesting as I can't think why a pause would be required.

Incidentally, earlier today I uploaded Edit a Recently Executed Macro, Version 2.0. The new version includes a few enhancements and one bug fix. I suggest you download it when you get the opportunity.

If you have any feedback, please do include it in that thread. Thanks.

Certainly; I didn't take it as such. I just like to help fix issues if they do arise.