I have 50 macros all sending a different email.
I have one macro which has the name of all the other macros as a selection.
User then selects 1 of the 50 macros and presses ok (the selection is saved as a macro)
KM then checks each of the 50 UIs to see which one has been selected then triggers that macro.
This process is very slow and takes ages, is there a work around this system?
If the user selected the 49th macro in the list then KM has to check macro 1-48 to see if it has been selected as the variable then execute the macro, this is time consuming.
It’s difficult to comprehend your workflow from the given description and images.
What I would probably do is use Dan Thomas’ Spotlight Search Prompt to pick the given email.
(Or Keyboard Maestro 8’s new Prompt with List action.)
I would then use the returned text in a find action. (Personally I’d use the Satimage.osax and AppleScript for this, but Keyboard Maestro’s search will work perfectly well.)
Your pick-list would look like this:
Requesting Email address for correspondence
Requesting Client updates their Details with Bank
Then you would find the first column in a list like this:
Requesting Email address for correspondence do script "XXXXX01"
Requesting Client updates their Details with Bank do script "XXXXX02"
Only the do script portion would be returned and then run.
For ease of maintenance I’d only use 1 list, and the macro itself would split it into column 1 for the Prompt with List action.
A workflow like this should be pretty easy to implement and very simple to use and maintain.
What does this mean? Selects how? How can the selection be saved "as a macro"?
If you want to select a macro using a popup menu, you could use the Prompt for User Input action and the How to Store a Different Value than Displayed technique to store the UUID.
Or you could use a Dictionary to map from names to UUIDs.
Or you could use a text file containing UUID:name, and grep the name, and retrieve the UUID.
macro action has a drop down box (each drop down box is the name of a macro)
user makes a selection
that Selection is saved as a KM variables
the 50 macros are triggered with all containing the Selection macro if variables matches then macro is triggered (please see attached)
Please could you explain these more?
If you want to select a macro using a popup menu, you could use the Prompt for User Input action and the How to Store a Different Value than Displayed technique to store the UUID.
Or you could use a Dictionary to map from names to UUIDs.
Or you could use a text file containing UUID:name, and grep the name, and retrieve the UUID.
This macro automatically lists the names of all macros that start with "SMS Create" in a dropdown box, then, upon making a selection, passes that macro's UUID to an Execute an AppleScript action that only executes that macro. It does so by populating the list with macro names written like this:
[UUID]__[MACRO NAME]
When variables with two underscores like this are used in a Prompt for User Input action, the text after the underscores is displayed in the prompt, but the text before the underscores is stored as the resulting variable value. Once we have the selected macro's UUID in a variable, it's easy enough to use AppleScript to tell the Keyboard Maestro engine to execute that specific UUID (the final action of the macro) as opposed to the list of 50 or so UUIDs you show in your OP.
Please note that using the macro I've shown here will require you to remove the If/Then action from each of these SMS Create macros, since with this method, the Reason for SMS variable now contains a KM UUID and not the macro's name (though honestly, I would recommend doing this anyway since with this method, the If/Then check is no longer needed). Fortunately in KM8, you can quickly remove the If/Then (or any other grouping action like Repeat, For Each, etc.) by selecting all of the actions contained within it and selecting "Degroup" from the Actions menu.
Incidentally, in addition to (or instead of) this prompt method, you could also use a macro consisting of a single Trigger Macro by Name action that is limited to your SMS Create macros, which would enable the kind of pick-by-searching functionality described by @ccstone and @JMichaelTX above. This kind of macro is very easy to set up, so I would encourage you to try this as well:
Please note that using this to trigger macros directly will also require you to remove the current If/Then check from them (though that's just all the more reason to do so, in my opinion).
Hah! Your response made my day. I’m glad my example macro proved so useful for you
Hopefully the macro and its AppleScript actions are self-explanatory enough that you can figure out how to adopt it to other groups of macros, but feel free to ask if you have more questions in the future.
If by “folder” you mean “macro group”, then certainly. Just add in macro group "NAME OF GROUP" after every macro in the initial AppleScript action, like this:
repeat with i in (every macro in macro group "Test" whose name starts with "Search")
Thank you once again, I just can’t believe how simple the code is in the Applescripts. If I was to write something I would probably write another sentence and it won’t work
Glad I could help! Fortunately (at least in this case) I’m still very much an AppleScript beginner, so this kind of simple script is all I can manage right now
KM prompts don't allow for multiple selections (unless you're capable of creating a custom HTML prompt, which I am not) so ironically, an AppleScript "Choose From List" dialog actually seems like one of the simplest ways to go about enabling multiple selections here. With the assumption that you're trying to select multiple macros to run (since the original topic was about optimizing selecting from a list of macros) here's a way of going about that. Please note that this script requires Keyboard Maestro 8.0.4 or later:
set MacroNames to {}
set MacroUUIDs to {}
tell application "Keyboard Maestro"
repeat with i in (every macro whose name starts with "SMS Create")
set end of MacroNames to name of i
set end of MacroUUIDs to id of i
end repeat
end tell
set MacrosAndUUIDs to {}
repeat with i from 1 to count MacroNames
set end of MacrosAndUUIDs to (item i of MacroNames) & ": " & (item i of MacroUUIDs)
end repeat
choose from list MacrosAndUUIDs with multiple selections allowed
set SelectedMacros to result
repeat with i from 1 to (length of SelectedMacros)
tell application "Keyboard Maestro Engine"
set MacroToRun to search item i of SelectedMacros for ".*: ([A-Z0-9-]+)$" replace "$1" with regex
do script MacroToRun
end tell
end repeat
And in macro form (as you can see, the rest of the steps from the other macro are no longer necessary, since the AppleScript now does all the work):