How to Choose Which Macro to Trigger Within Another Macro

Let me try and explain the title a bit better. I have a group of macros (there are about 30 of them, they all do the same thing, but with different details depending on different typed string triggers), and I want to be able to trigger a selected one of them from within another main macro. This main macro opens a dialog when it starts and asks me for several variables. One of those I want to be able to choose which of the 30 or so macros in the group gets triggered.

Basically I run a venue and have to frequently mail out crew information emails, and these always contain the contact details of the crew for that event in a small spreadsheet. The 30 or so macros I have add the name, phone number and email address of each crew member, and also adds their email to the recipients of the email.

So if I type =as= it triggers the macro for the person who's initials are A.S. etc etc. The main big macro basically creates the crew info email. It fills in the event name, call times, running times, etc etc. all from the variables in the initial query it pops up. And it asks me who is in each of the roles but I currently leave that blank and then do that part by manually triggering the relevant macros because as I can't work out how to do it automatically from within the main macro.

I can't see a way with either sub routine or trigger macro to be flexible about which other macro it triggers. And when you get KM to type text it doesn't evaluate that as a trigger string. Is there a better way to achieve what I'm trying to do?

Sorry for the long babble, but I wanted to be clear. Thanks in advance

Can you post an example macro so we can see if there's a simpler way of doing it than using a macro for each person?


Here is an example (all personal info has been changed) of one of the crew details macro.

I had thought of making these part of a bigger macro with switch grouping for each person, but then I would need to make that open up a dialog asking which person – and this adds an extra step.

This is fine for the automated version, triggered from my main macro, but adds an extra tedious step for the occasions I need to do this manually (which I would still like to keep these available for triggering manually from a text string).

Adam Stanley copy.kmmacros (4.5 KB)

Would this work for you? You'd add entries to the list at the top, with each line's details (name/number/email) separated by a comma (no space). Triggering the macro will present you with a searchable list of names and hitting enter will fill in all the details as per your original macro. One advantage to doing it this way is that you only need to maintain one macro.

Fill In Details.kmmacros (28 KB)

Macro screenshot

Hey Dan,

What app are you working in? Apple Mail? Or something else?


Like @noisneil I think you could go about this in a simpler way. Rather than have a Macro for every crew member, have all the crew members details in one "database" Variable and then draw the data from that.

The goal would be for you to only have to enter the actual data for each crew member once.

Again like @noisneil I would suggest you put all the crew members into one Variable, a line for each name and their data separated by a comma.

This example Macro then shows how you could make use of that to make an email about the event. It isn't laid out in any special way as I don't know how you would like to do the layout of your email. But it shows how just one Variable of data and one single prompt in a single Macro can do the whole job. The good thing is that when you have to add or delete possible crew members you just have to edit that single Variable at the top of the Macro and the rest of Macro will adjust.

EXAMPLE Crew Choice Email

EXAMPLE Crew Choice Email.kmmacros (6.4 KB)

Click to Show Image of Macro


This is absolutely brilliant, thank you so much! I think somewhere between the two solutions I will be able to make something that suits my use case. I have to say I don't fully understand all the variable handling in either of your examples, so this will be a great learning opportunity for me.

@Zabobon I use Outlook for the emails as I find it is the best for the way it connects with the exchange server for that company. An we all use a lot of shared templates etc, so it is jus best for me to stick with the microsoft 365 world. It's a shame there isn't a way of creating an email directly within that as in your Mail example, but I can get around it with a bit more fiddling as I have with another macro.

great stuff, I am loving KM more and more every day I spend with it.


Hey Dan,

Historically Microsoft Outlook has been very AppleScriptable, although I've heard that the latest version is lagging behind in this.

** I only have Microsoft Office 2016 to test with, so I'm not certain of my facts...

I believe I saw that Microsoft is going to fix this sometime in the near future, but I'll believe that when I actually see it.

If and when AppleScriptability returns to Outlook you'll have a great deal of flexibility in automating email.


You might have already worked this out. But all you would have to do is set the last Action of the example Macro to put the output onto the System Clipboard and then you could ⌘V paste it in to an Outlook email. You could even automate more by having Keyboard Maestro open Outlook, make new blank email, go to body of email and paste.

Click to Show Image of Macro

EXAMPLE Crew Choice Email v2.00.kmmacros (5.4 KB)


@ccstone's right in that the latest "New" Outlook is rather broken, but if you've managed to stay on "Old" Outlook (you'll have a "New Outlook" toggle in the main window's title bar, set to "Off") everything works fine.

(The other way to check is "can I make a new Contact List?", which is a menu item in New Outlook but remains permanently greyed out! Yep, and email/calendar/contacts manager in which you can no longer make a list of contact -- go MS!)

I've been forced to Outlook at work too, so have been working through similar...

1 Like

Interesting info about the scriptability of the old Outlook. I didn't realise it was possible to switch to that interface, so I've now switched my Outlook interface to the 'Old' version. I might look into scripting it as when I open my template email it is inconsistent as to where the cursor is, and therefore what keystrokes are needed to get it in to any of the fields like subject, or the main body. I can't find a shortcut to go directly to anywhere useful.

My AppleScript is not great, but I don't think I need to do anything complex with it here.

It's not just the interface, you get a whole bunch of missing functionality back, including AppleScript. So you'll now be able to do:

tell application "Microsoft Outlook"
	set theMsg to make new outgoing message with properties {subject:"I am a test", plain text content:"Put some body text here."}
	make new to recipient at theMsg with properties {email address:{name:"Test Account", address:""}}
end tell

...and see a new outgoing message appear in your Drafts folder. And you can build your content earlier in the script (or in KM if that's easier) and pass it in as a variable, using HTML if you want styled-text emails.

It really is easier than trying to script the UI.

1 Like