MACRO: Get Recently Run Macros with Last Executed Time

Apparently I wasn't clear enough.

I get this funny result.....

when I execute the action only and when I execute the macro only.

Try actually triggering the macro instead of using “Try”.

1 Like

now it works! thanks

1 Like

Hey Folks,

I ran across this topic while researching something else, and I felt like fiddling with the shell for a bit.

The user can select the last N most recently run macros with a user-setting.

(The macro automatically excludes the last instance of itself.)

23

-Chris


KM -- Last N Macros Run v1.00.kmmacros (5.8 KB)

3 Likes

Hey Folks,

Here's one that gets only the last macro run.

(The macro automatically excludes the last instance of itself.)

33

-Chris


Download ⇢ KM -- Last Run Macro v1.00.kmmacros (5.2 KB)

1 Like

This macro has been incredibly useful. One issue I've run into is that I have a few small macros that run whenever I switch apps (maintaining Stream Deck icons), so the list will often look like this:

Screenshot

If anyone has any ideas on how to filter out certain results from the list, that would make it a lot more readable.

1 Like

Okay @noisneil, I'm sure this could be improved, but here's something I hacked together:

  1. First I modified @ccstone's macro above to create a subroutine.

    DOWNLOAD Subroutine File:
    sub—KM -- Last N Macros Run v1.00.kmmacros (26 KB)

    Subroutine-image

  2. Then I created this macro to call the subroutine and filter unwanted macros. Note that you'll want to modify the contents of local_Macros to Exclude

    DOWNLOAD Macro File:
    Last N Macros Run (Filtered).kmmacros (32 KB)
    Note: This macro was uploaded in a DISABLED state. It must be ENABLED before it can be run. If it does not trigger, the macro group might also need to be ENABLED.

    Macro-image


@noisneil, there's one known limitation. If the macro name includes a close parenthesis the If action that includes matches will not successfully match.

For example, I have a macro named: 01)Toggle Smart Sort. If I put that exact string in local_Macros to Exclude then the filtering fails. (Note: I suspect that this is a Regular Expression issue, but even when I attempted to use the Filter ActionEncode for Regular Expression, the filtering failed. Maybe @ccstone, @drdrang or some other RegEx Ninja could explain.)

The good news is that the macro can be filtered if a substring of the macro name is entered in local_Macros to Exclude (in this example: Toggle Smart Sort).

1 Like

Do you need a regex? I haven't fully followed the logic of the macros, but can you not use "contains" (which is also case-insensitive) instead of "matches"?

Unless it's because you want to include regex pattens in your exclusions list, in which case @peternlewis's post here might help.

Thanks @_jims. Very nicely put together and that filtering works perfectly! None of my macro names start with parentheses but quite a few have them near the end of their titles. All I've had to do is cut the name short and it still finds them. :+1:t3:

The ideal scenario would probably be to do the filtering on the shell script side (not that I'd have a clue how of course), just because there are so many instances of those little macros, that I have to request a silly number of results. Here's what I get from requesting 500 results, which takes 12sec to process:

Screenshot

Nice thought regarding contains but I couldn't get that to work.

I was hoping to use RegEx specifications due to the flexibility. Unfortunately I wasn't thinking straight when I posted the macro earlier.

The problem is easily resolved by escaping the special character. In addition, I added a prefix (⇢ ) and suffix ($) to each macro in local_Macros to Exclude to prevent unintended matches.

Keyboard Maestro Export

Okay @noisneil, now that I look at the approach I used above, I'm embarrassed. I need to get more sleep. :crazy_face:

This is much more efficient:

DOWNLOAD Macro File:
Last N Macros Run (Filtered—Method 2).kmmacros (27 KB)
Note: This macro was uploaded in a DISABLED state. It must be ENABLED before it can be run. If it does not trigger, the macro group might also need to be ENABLED.

Macro-image

1 Like

Sooo much quicker! The only downside is that, now that it's looking for a new line directly after the macro name, I can't shorten the name to exclude the trigger. As some of these macros are triggered when any application activates, the trigger could be anything.

The previous (less efficient) version is more forgiving in that regard.

It should work if you add a .* suffix. For example:

Speakers - nAc Volume Profile \(per App\).*
1 Like

Brilliant. I changed the regex to .*⇢ %Variable%local_Exclude%.*\n and it works nicely. Thanks @_jims!

I tried to automatically escape special characters, but it doesn't seem to do anything. Any idea what's wrong with it? Be handy to know for other applications.

Edit:

This action works:

Escape Regex Special Characters.kmactions (643 Bytes)

@noisneil, here's another spin on this topic.

This macro leverages @ccstone's excellent macro (recast as a subroutine) to generate a list of the most recently executed macros (filtered) presented in a Prompt With List (most recent on top).

When a macro is selected, it will be executed.

If the Shift (⇧) is down when it is selected, the macro will be found using Edit>Find>Find in All Macros….



DOWNLOAD Macro File:
Execute or Find Recent Macro.kmmacros (32 KB)
Note: This macro was uploaded in a DISABLED state. It must be ENABLED before it can be run. If it does not trigger, the macro group might also need to be ENABLED.

Macro-image


Required subroutine:

DOWNLOAD Subroutine File:
sub—KM -- Last N Macros Run v1.00.kmmacros (26 KB)

Subroutine-image

2 Likes

@_jims, Love the idea of this, but at the moment I'm getting an empty list.

@_jims

The output of this action is blank, and I think it's the point of failure:

Any ideas why the script might not be working on my system?

Hi @noisneil. Sorry for the delayed reply.

Try downloading the main macro again (above). I think I may have mistakenly uploaded an incorrect version. Also, in this updated version I replaced tac with tail -r in the shell script. tac may not be available on your system.

After testing again, if you have any issues, please let me know.

1 Like

Yep, that was it! Really nice. Thanks! :clap:t3::clap:t3:

1 Like