Creating a "preparation" macro

Some of my macros require applications and browsers to be "setup" before I can run the macro. I might need Safari to be in a certain position, Firefox to be in a certain position, and Photoshop to be in a certain position with a specific tool selected, before I can run my macro. This is due to Move and Click actions where the mouse needs to be in a specific spot for a step to work properly.

My 2 thoughts are:

  1. take a screenshot of my desktop so I know where everything should be, and take exact pixel dimensions and then somehow store that information and screenshot in my macro for future reference.
  2. make a preparation macro that will automatically open those applications and move/resize them where they need to be.

What do you guys normally do? Any recommendations?

If at all possible, I would honestly recommend changing the macro so that it doesn't use move and click actions that rely on certain elements being in exact coordinates on the screen, as actions like that should generally be more of a last resort, but assuming that's not possible and there's nothing that could substitute for these clicking actions, I would go the preparation macro route and ensure each app is open and where it needs to be.

I'm definitely not a fan of move and click actions and they're always a last resort for me. I usually try to use key presses and even test different browsers to see what I can get away with before I resort to move and clicks. I'm kinda stuck with absolute positioning for some of my macros though.

I'm not sure what cliclick is and am a complete novice with scripting. :expressionless:

I've been working on a preparation macro and am about half done with it...seems to be working so far.

If at all possible you should avoid using absolute screen coordinates.
In the Move and Click Action you can set the location relative to other objects, like the Left,Top corner of a window.

I don't use a "preparation" macro. I just select the app and window of interest just before the Move and Click Action. This has worked very well for me.

I should have clarified, I use relative move-and-click positions if possible, but there's one instance where I do have an absolute position because I need to have Photoshop open and then do a click-and-drag with Photoshop in the foreground, dragging over to a browser in the background (to obtain a hex value using PS's color-picker).

I am a bit confused here: can someone give me an example of something that is “not clickable” by KM please? Because I understood @gglick to mean that if there is no programmatic way to automate something (like with AppleScript or Javascript for example) then the last resort is to use mouse movements and mouse clicking. I had a quick look at clickclick and it seemed to me to do nothing more than what KM can do.

Apologies if I’m being thick here!

You should still be able to use a relative coordinate to calculate the absolute coordinate you need for drag/drop. something like this:

StartDragX = Window.Left + RelativeOffset.X

I've dealt with this for a long time, across multiple computers, with multiple set-ups, including multiple monitors (each of which has its own pixel dimensions).

My conclusion was that if there is a system that is foolproof, it is not worth the cost of implementing. Put another way: I've had to accept that my KM macros are not programs, and will never be as robust (and fool-proof) as programs (because I will never spend the time to make them so). They are my aides and helpers — and they often require that I set the scene for them to do their work, and will need to be updated to match changes in the programs that I use.

In practice, I do the following:
. use machine/set-up specific version of Macros (I have never had more than three set-ups, so this is effective even while inelegant). So "do this on my laptop with no external monitor" is different from the Macro "do this same thing on my desktop with three monitors".
. set all windows to maximized all the time. This allows me to rely on "relative to window" and "relative to screen" coordinates.
. never use "Full Screen" mode. I've never liked it, so this doesn't bother me.
. have as the first Action in every Macro a comment that I keep updated in which I list the necessary screen and set-up conditions for the Macro to successfully run. This also serves as a running log of any changes I make to the Macro (a manually-updated log).
. and (already mentioned by others) use graphic-dependent actions as little as possible. It's humanly silly, but not computer-silly, to repeat "Type Tab key" twenty-seven times rather than click on the purple bit with the yellow thing.

I run a one-person shop, and my Macros are executed by only me. The above has worked. HTH.

With the same caveat that moving and clicking on a specific point is something I try and avoid but sometimes just can't...

I find the "If Then Else" action very useful so that the same Keyboard Maestro macro can work on my different computers which have different screen sizes and layouts. The specific Mac's name just has to be included in the action.

In this case the example below is part of a macro I use in Final Cut Pro X which I run successfully on my laptop and my desktop computer. (I sync my Keyboard Maestro Macros using Dropbox.)

I've found this approach is very robust and I've been using it for a couple of years without issue. If I change or add a computer I just add in another of these "If Then Else" actions for that particular Mac.

And to make sure the windows and layout is consistent in Final Cut Pro X I have a saved "Workspace" in Final Cut Pro X and the Keyboard Maestro macro includes an earlier step, to restore that saved Workspace.

User defined Workspaces are a feature of Final Cut Pro X - but Photoshop and Illustrator (and probably many other applications) all allow saving of user Workspaces/Window positions etc.

And for applications that don't have that feature I use Keyboard Maestro to set up the windows to be consistent each time the macro is run.

And again, those Keyboard Maestro actions could be used inside "If, Then. Else" actions to make them specific to each particular Mac.


For multiple (more than 2) cases, e.g. Macs, I find that the KM Switch or Case action to be easier to use and maintain than multiple IF/THEN Actions.


Ah. That is very interesting. I had never used the "Switch Case"action before. Amazing that Keyboard Maestro has so many layers of subtlety.

So, would I change my example above to this?

And how would I use this for a nested list of conditions (if I wanted to specify a computer and a certain app?)

Here is a macro I use to specify what ⌘M does on different computers (where my main computer "Venus" has dual monitors). At the moment it uses a nested "If, Then, Else" action.

20)Maximize (KM).kmmacros (6.0 KB)

I think I have worked out the answer to my own question. I'd have to put the nesting the other way around to use the "Switch Case" action. So, start with testing what application is at the front, then test to see if my main computer was the computer running the macro. And in this case this actually increases the number of steps needed but still seems to work fine.

I think I never checked out the "Switch Case" action before because I thought it was something to do with upper and lower case in type :joy:

Using Switch Case is NOT always the best answer. You have to judge each situation on its own merits. I use lots of IF/THEN Actions.

Yes, I can see that now. Thanks so much for mentioning Switch/Case as I hadn't realised what it did before. It works really well as a simple and easily editable way of fine tuning a Macro to work on different computers and I'll use it for that from now on.

Yes, I agree. Keyboard Maestro is such a robust and quick solution to speeding up workflows. I have macros that I have bashed together to help me with a particular task that I find I have to repeat a lot and where the app or apps I'm using don't have an inbuilt solution. Sometimes these macros aren't pretty - but the great thing is they work. If I find I'm using them a lot I go back in and refine them and try to make them more robust.

What I love about Keyboard Maestro's modular approach is that any action in a macro can be refined or replaced with a better action and the macro carries on working and doing its job. And since these actions can be either built-in Keyboard Maestro actions or ways of including lines AppleScript or User Prompts for Variables etc, the combinations possible are pretty much limitless. And that is even before taking into account all the ways of triggering a macro...

@Zabobon, I see you created some manual quotes. It will work better if you use the Forum quote tool. Just select the text and you'll see a "Quote" popup. Click that.
That will create a quote with the author identified, and create a reply if needed.

Thanks. I've gone back and edited my posts to put the quotes in the correct format.