Run macro from another macro

If you must see it, it’s unlisted on YouTube because I didn’t take the time to polish it:

(I like to only put polished videos as public.)

This was a quick-and-dirty demonstration of a simple technique in Digital Performer.

I’ve just learned about Found Images, which will be a fun trick to add to techniques like this so that the macro is even more bulletproof.

1 Like

Hey David

Found images is powerful if a little slow and processor-intensive.

Keyboard Maestro “Generic-Test 01” Macro

Use Cmd-Shift-4 and hold the Control-key down to copy to clipboard.

Click in the little box graphic field.

Paste.

Turn on 'Display'.

Test.

-Chris


(A KM7 macro — which may or may not import into KM6.)

Generic-Test 01.kmmacros (20 KB)

This is actually a bit intentional. The idea with Keyboard Maestro is to make the very basic creation of a macro simple - do the Tutorial to see the process and it is very quick and easy, familiar to everyone who is well versed in Keyboard Maestro.

But Keyboard Maestro is extremely powerful. If all that power was immediately apparent, most people would take one look and run away screaming. And that would be a shame, not just because it would be bad for my business, but because those folks would miss out on the value they could get from Keyboard Maestro.

So Keyboard Maestro is designed to allow you to relatively easily create simple macros that can do simple tasks. And often one single macro like this can be worth the purchase price alone. And now you get the rest for free. And then, when you're comfortable, you start digging a bit and you see just how many actions there are, and how many other triggers there are, and how you can use the text tokens and the functions to do all kinds of stuff, and that there are loops and branching conditions, and collections, and the possibilities are essentially endless. But if you saw it all right at the start it would be extremely daunting.

As for documentation, I agree, but I don't see a better solution. There are endless sources of informations:

  • Direct support.
  • In-built help (including the tutorial)
  • The documentation.
  • The wiki.
  • The forum.
  • and yes, YouTube.

I wonder if it is possible to build a google search page that searches all of them.

But, as I say, I'm not sure there is a good solution to this. I could get rid of the documentation, and just use the wiki, and I may eventually do that (certainly that is the direction I'm moving in). But the forum provides different stuff, and the direct support is always needed, so it only helps in a limited way.

Great video tutorial on Digital Performer - thanks for sharing!

Hey David,

Make it public. It's good enough, and there are other folks on the forum who are interested in making macros for Digital Performer.

-Chris

Thanks. I do like to polish my videos a little more and put my branding on them, etc., but I will definitely consider making more videos in this vein as I learn new tricks.

So my quick-and-dirty videos for friends or closed communities are private/unlisted, but the good ones are public.

Hey David,

In the vid you say Keyboard Maestro cannot show the screen position of things, and therefore you use record to get the location.

In KM6 there is not a built-in cursor-discovery-tool, but several of us have rolled-our-own.

In KM7 there is such a tool..

-Chris

Ah, great! This is quite handy. I migrated from iKey, which had a one-click button to “sample” the current location of the mouse. (You would click the “sample” button, then move the mouse to your desired location, then hold down the command key for 2 seconds, and iKey would record that exact location in absolute x/y coordinates.)

My video was made in KM6, which is why I didn’t know about this (and another reason I’d rather revise the video before making it public). I just checked in KM7 and am SO pleased to find this new “Get” command, which I’ll be using all the time, for sure.

Thanks Chris!

I've successfully migrated numerous TextExpander (TE) snippets to Keyboard Maestro (KM) macros triggered by typed strings! However, there are some macros that need to call other macros with a specific typed string because there are multiple typed strings to trigger the macro and I'm not quite seeing how to get this done with KM. If nothing is required to be passed, I have successfully triggered a macro from within a macro as shown below.

For the simplest example, I have a snippet 'filetrbl' which expands as "Railcar Trouble Report - %snippet:-cdt%" providing the filename of a file to be downloaded. The '-cdt' snippet expands to provide yesterday's date for inclusion into the filename. The '-cdt' snippet has already been migrated to KM, but it doesn't get invoked when I enter 'filetrbl' into the finder window for downloading the file.

I have other migrated macros that fill in text for the body of an email message using '-sdy' (last Sunday) and other date typed strings that don't get expanded. See the macro shown below for creating an email message requesting payroll summary information. Lastly, the documentation for running a macro from another macro recommends using the "Execute a Macro" action and that there should be a "With Parameter" option, but the actual available actions don't have a "With Parameter" option.

Keyboard Maestro “Test Payroll Summary Request Email Snippet” Macro

Test Payroll Summary Request Email Snippet.kmmacros (5.0 KB)

Keyboard Maestro typing will not trigger Keyboard Maestro’s Typed String triggers.

Instead, use the Execute Macro Action where you would otherwise type something to expand another snippet.

Or perhaps a more Keyboard Maestro way of doing it would be to have a macro group full of macros who just determine some information and store it in a variable that you can use in other macros. For example:

Macro "Set Yesterdays Date For Files"
Action: Set Variable “Yesterdays Date For Files” to text “%ICUDateTimeMinus%1%Day%yyyy-MM-dd%”

Then your -cdt macro looks like this:

Macro "cdt"
Trigger: Typed String -cdt
Actions: 
Execute Macro "Set Yesterdays Date For Files"
Insert Text by Typing "%Variable%Yesterdays Date For Files%
Macro Test Payroll
Trigger: F1
Actions: 
Execute Macro "Set Yesterdays Date For Files"
…
Insert Text by typing "… Week Ending: %Variable%Yesterdays Date For Files%

Sorry, I’ve clearly mixed and matches your macros and text, but hopefully you get the idea - separate the calculation of the values from the typing of the results so that you can use the calculated value in different macros.

Peter,

Thanks, I think I’ve understood your recommendation.

Your guidance indicates that although I have a macro with multiple triggers for determining last Sunday and numerous other days or dates often called upon as typed strings, I can’t use it from within another macro. Certainly in the case of yesterday’s date where it can be determined without logic, its easy to accomplish without the macro. Still I’ve reduced the number of individual snippets using KM and I’m pleased and appreciative.

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