I just learned about smart groups and how to use them in Trigger Macro by Name action. I have a smart group that displays macros used in the last 5 minutes. But the smart group result is shown in alphabetical order. Is it possible to sort the smart group result by date used? Thanks!
Then you are going to have to use AS or JXA to build your list, collecting {macroUUID,macroName,releventDate}, sort that list by releventDate, and present the result in a dialog.
Since you'll have to open the KM Editor (unless you want to parse the entire plist) you might as well write a macro that selects the appropriate Smart Group, sets the sort order, and selects the first macro in the list ready for you to arrow/type to any other. Something like:
Appreciate the solution @Nige_S. However, my main use case is the run the macro from smart group's result list. On occasions when I want to edit the macro, it opens KM Editor to that chosen macro. I try not to change the KM Editor's sort order for macros.
Here's a version that does your "Edited in the last 3 days". By default it executes the chosen macro, if you hold down ⌥ while selecting a macro it will open it for editing instead:
Yes -- and from the Editor you can select a macro and run it with either the "Run" button, File -> Run Macro, or with a shortcut (⌘R for me, you might have to set your own in System Settings or with a KM macro).
However, the AS version isn't too bad and -- importantly -- isn't too slow, even when pointed at "All Macros".
Hi @Nige_S , I'm getting this error in the KM engine when running the macro.
2024-11-28 17:26:54 Execute macro “Modified in Last 3 Days” from trigger Editor
2024-11-28 17:26:54 Action 16399067 failed: Execute an AppleScript failed with script error: text-script:34:76: script error: Invalid date and time date Thursday 1 January 1970 at 00:00:00. (-30720)
2024-11-28 17:26:54 Execute an AppleScript failed with script error: text-script:34:76: script error: Invalid date and time date Thursday 1 January 1970 at 00:00:00. (-30720). Macro “Modified in Last 3 Days” cancelled (while executing Execute AppleScript).
The creation date and modification date both work perfectly. They match exactly what KM Editor is showing when sorted by creation date or modification date.
However, the used date does not match what KM Editor is showing. set macroList to every macro of smart group "All Macros" whose used date > ((get current date) - (5 * minutes))
The Apple Script works for me but the whole macro does not.
set outText to ""
set baseDate to date "Tuesday, 11 July 2006 at 00:00:00"
tell application "Keyboard Maestro"
set macroList to every macro of smart group "All Macros" whose modification date > ((get current date) - (3 * days))
repeat with eachMacro in macroList
set outText to outText & ((modification date of eachMacro) - baseDate) & tab & id of eachMacro & "__" & name of eachMacro & linefeed
end repeat
end tell
return outText
But if the user wants to know the least used macros (and maybe their last use)?
How to change this line?
modification date > ((get baseDate?) - (3 * days?))
We can't troubleshoot unless you say in what way it doesn't work.
Then the user should go to the Editor, select the "All Macros" Smart Group (or a Group of interest), and sort by "Use Count". That information isn't directly available via AppleScript.
But you could take a look at some of the other recently-posted macros that list macro information -- one of those might do what you want by querying the database which stores that info. And keep an eye out for @DanThomas's forthcoming Macro Explorer, there's a usage count column in the screenshot.
Then maybe you don't have any macros that match the criteria? If you don't have KM Engine Notifications turned on you won't know that the macro has errored because of an empty list.
I'd just use a Smart Group for a one-off like this. Sort by "Use Count", scroll to the bottom of the list (you can't reverse-sort), show the Macro Inspector, use the arrow keys to move through the macros and ⌘⌫ to delete the ones you don't want.