Run macro from another macro

No, that is not correct - you can use that macro via the Execute Macro action, you just cannot trigger it via the Typed String trigger from Keyboard Maestro’s typing.

So in your Test Payroll example, remove -sdy from your Insert Text "Gentlemen…" action, and after that action include an Execute Macro "whatever the sdy Macro is Called".

Ok, my bad! I can’t trigger it from within a macro using the “Insert text by typing” action.

I still don’t see how to Execute a Macro with parameter which it appears I should do for a macro with multiple triggers. Is that right?

You can add a parameter to the Execute Macro action via the gear menu, and it will be available via the %TriggerValue% token in that target macro.

But I don’t really understand what you’re doing with your macro with multiple triggers to know what you are really trying to do.

Peter,

Sorry to be so much trouble, I greatly appreciate your patience!

To explain, I've migrated many little TE snippets to KM macros and where I could expand many of them using a single macro, I did (see example below). So while I understand your recommendation of triggering a specific macro from another macro to determine a date in my preferred format, for example, I don't want to recreate again a number of small individual macros. That's why I'd like to trigger the macro using the particular string. Using the Execute a Macro (adjusted with the gear) with a parameter should be just what I need!

Keyboard Maestro “Days of the Week & Dates of Days (Past & Future)” Macro

Days of the Week & Dates of Days (Past & Future).kmmacros (23 KB)

By the way, is this the type of macro that's well suited to use the regular expression match feature?

2 Likes

Wow. Yes, as long as you only use the %TriggerValue% and not the %Trigger% which I see you record in the macro at the top, then that should work fine.

Impressive macro.

You should post it to the macro category.

Hey @KM_Panther,

Yes, that works well.  :smile:

Sure.

This macro uses a Typed-Trigger with a Regular Expression to calculate the number of days ± from NOW() and pastes a formatted date-string.

NOW() == Thu, May 19, 2016

So:

 -10d == Mon, May 09, 2016
 +10d == Sun, May 29, 2016

I have limited this example macro to days and the number of days to nnn (or 999 max), but it could be made to be very sophisticated.

-Chris


Number of Days from Now.kmmacros (4.1 KB)

Peter,

I’m happy to share, especially considering all the assistance I’ve received here! Perhaps someone will be able to come up with the correct regular expression to properly capture the typed string triggers as I’m new to that too and haven’t been able to develop a working regex. I know this one fails:

(^[+|-]?[+|-]?[f|F|m|M|s|S|t|T|w|W]?[a|A|h|H]?[d|D][y|Y])

Yeah, I see I confused the results of the %TriggerValue% and %Trigger%. I lucked out as I used contains to check it, but I’ll change it before posting.

Thanks again.

Chris,

Now that’s truly impressive! I’ll examine how I might incorporate your approach into mine, but will post it to the macro category as is since Peter suggested it.

Thank you

So you want to trigger on the sequence:

  • nothing or - or – or + or ++
  • s or m or t or w or th or f or sa
  • dy

So the regex is pretty easy:

(?i)(|-|--|\+|\+\+)(s|m|t|w|th|f|sa)dy

No need to over complicate it, this clearly explains your intentions - case insensitive, one of these, one of those, end in dy. I’m not sure why you want it case insensitive, but maybe your macro does different things with different case letters, I didn’t check that closely.

the ^ at the front is not necessary, Keyboard Maestro will always match to the end of whatever you have typed.

[+|-] is both wrong and invalid. [] contains a set of characters, so the | is not needed. And - can only be the first character otherwise it starts a range (as in [a-z]). So if you wanted a-z and hyphen, then you would do [-a-z]. In this case you would use [-+] (not [±]).

1 Like

Peter,

Your post makes coming up with the regex seem so easy, but I was just struggling seeing that! I like the way your bullets break it down, so I’ll need to be sure to write what I want from the regex that way going forward.

However, if I’m understanding, I think (|-|–|+|+) should be (|-|–|+|++) so that both pluses could be captured to find the ++ option entry.

Many thanks

It is the way you need to think about regex when you make them - which coincidently is very similar to the way you need to think about a macro when you make it.

Yes, I missed a + - and you need the \ before the + because + means "one or more" of the preceding item.