Action that gets triggered only when something occurs

Let's say I have Action 1> Action 2> Action 3> Action 4
Can I have an action (let's call it Action X) that runs on different positions based on when the computer reacts a certain way?

For example, with Firefox, there's this window that doesn't show right after I start it (it's the Global Password window). So between starting Firefox and that window showing up, I would like KM to perform some actions, instead of waiting for the window to pop up. And then when the window pops up, the macro gets "interrupted", runs that extra Action X and once it's done, resumes the macro.

So sometimes it will be
Action 1> Action X> Action 2> Action 3> Action 4
Action X> Action 1> Action 2> Action 3> Action 4
Action 1> Action 2> Action 3> Action 4> Action X

Just put action X in its own separate macro.

I'm a bit confused... how would that achieve the result I'm looking for?
My goal is that the action gets triggered when something happens on the screen, but it's unpredictable. Sometimes it will run 1 second after the main macro started, sometimes it will run right away, sometimes 10 seconds later. So the goal is that the main macro is "listening" to what's happening and when a particular thing happens, the main macro pauses, runs Action X and when it's done, resumes the main macro.

Again, I'm not sure how your suggestion would achieve this...? Can you clarify?

The way you've described it, the point at which Action X is executed doesn't seem to matter, and the other actions aren't dependent on it. Therefore you can put it in its own macro. Multiple macros can run concurrently, so Actions 1-4 can be running along nicely and Action X can run independently without interrupting the others.

Of course its hard to know for sure without knowing what any of these actions are trying to do.

Oh I see what you mean.
The issue is that they are somehow dependent, that's why I need the main macro to pause, let Action X run, then resume, because once that password window pops up, certain actions don't work such as CMD+T to create a new Tab, which would mess up the whole flow.

So would it be possible to achieve that of pausing the main macro, run Action X, then resume the main macro?

And you only want action X to run once? The quick way would be to chain multiple conditionals:

Set variable haveRunX to false
If condition, action X and set haveRunX to true, else action 1
If condition AND (haveRunX is false), action X and set haveRunX to true, else action 2
If condition AND (haveRunX is false), action X and set haveRunX to true, else action 3
If condition AND (haveRunX is false), action X and set haveRunX to true, else action 4
If (haveRunX is false), action X

1 Like

Beat me to it, as I was watching the Masterchef final with the missus.

Not sure if our thinking is the same, but this is what I had in mind:

Action X.kmmacros (20 KB)

Macro screenshot

Actions 1- 2- 3 & 4.kmmacros (28 KB)

Macro screenshot

It's a bit longwinded for something so simple, and does make me wonder why there isn't a Pause Other Macro action built in to Keyboard Maestro.

Of course, this doesn't rule out failure if any of the actions 1, 2, 3, or 4 take long enough to run that they overlap with the window popping up that triggers action X. It really depends on what they do.

I used 4 actions as an example, but this could be something with 30 actions.
My goal was to build something that would work regardless of the number of actions and wouldn't force me to build super complex conditions (which mean extra actions on top of the already used actions for the macro).

It might help to see your macro or at least know what you're trying to do. Perhaps there's a way of doing what you're aiming for a slightly different way. Or not...

That aside, I do think you raise an interesting point here. It would be good to find an efficient way to pause a macro if something that would interrupt its operation occurs.

As I mentioned on my reply to @Nige_S suggestion, I used 4 actions as an example, but my goal is to not be stuck on the number of actions I have, but something that would be automatic. Something as simple as:
"Hey, macro, there's this action on stand-by. Start running your actions, but once this action is valid, let the current action run, then stop everything. Run the stand-by action and once that's done, resume what you were doing".

Maybe this is not possible at all... or at least, not in a simple and easy way

The macro is pretty simple. It's just a few "open app", paste a URL, click some areas of the website. Nothing fancy. But once that window pops up, nothing else works and it being so unpredictable, it's hard to know when that will happen...

Do you want that window to pop up every time you open Chrome? If not, perhaps there's a way to avoid it?

This is actually Firefox and it's part of their feature called Sync, I believe. And it's silly, because unlike the native KeyChain, Firefox shows all passwords to anyone who knows how to go to Firefox's settings page. The only way to lock this is by setting a master password and by setting that master password, every time you open Firefox for the first time, you get this annoying pop up.

1 Like

For the sake of expediency, I'd probably use one of the above ideas. Yes, it will look a bit cluttered, but hopefully you won't have too many macros that are interrupted by that pop-up, so until a better solution presents itself, at least you can be up and running.

Had an idea.

Actions 1- 2- 3 & 4.kmmacros (23 KB)

Macro screenshot

Action X.kmmacros (22 KB)

Macro screenshot

For demo purposes:

  • Trigger the Actions 1, 2, 3 & 4 macro.
  • While the numbers are appearing onscreen, trigger the Action X macro.

You'll see that the Action X macro interrupts the other macro. When it's done performing its actions, it closes the debugger window and the Actions 1, 2, 3 & 4 macro resumes.

These aren't super-complex conditions. It's one condition per action and, they way you've stated the problem, any check after the first one is the same and adding another action just means duplicating the "If..." action and setting the "else" part to be the action you are adding.

But all this may be academic -- wouldn't it be better to force the dialog at the beginning rather than trying to work your way round the variable delay? Just make the first page you open be "about:logins", and that could solve the issue the easy way...


@Nige_S, what you think of the debugger idea? Seems like a Pause Other Macro action wouldn't be hard to implement, as the function is essentially the same. Only difference is that you'd target a single macro and the debugger window wouldn't open.

Honestly? I'd put it behind a break-glass with a big "Do not use except in case of Emergency!" sign :wink: Borrowing a term from semaphore locks -- "deadly embrace", where two (or more) macros have created a mutual pause that can't be broken...

I know I'm new here, and my piddling around hasn't created anything anywhere near as complex as the macros an experienced person can write, but my gut feeling is that this problem can nearly always be solved by changing the underlying logic -- we just need to remember that we shouldn't be automating what the user does, but automating a process that achieves the same goals (eg the recent "Save/New Folder" problem -- a user might do "New Folder" from the "Save" dialog, but a macro will be more robust making the new folder with an action then using that for the "Save").

In this case, I'd think that @iamdannywyatt could split the macro -- macro A that runs the password-requiring action, pauses until complete, then runs all the other actions that depend on that being complete, and macro B that has all the actions that don't depend on it. You'd then call macro A, asynchronously, as the first action of macro B.

Yeah totally agree, and first suggestions were about trying to get everything done rather than how to get it done your favourite way. However, the debugger thing does seem to work very nicely and could be useful in certain scenarios if all other options have been exhausted. Not sure what you mean about the "deadly embrace". It's one macro pausing all the others for a sec and then letting them run.

I guess I'm just interested, from an academic standpoint, in whether there's a way to pause a macro externally. This seems to do that, albeit in a slightly janky way.

I really should have quoted the following sentence instead -- the Pause Other Macro action. If that arrived and became a "general solution" to all things pausey, how long until someone -- probably me! -- has a control macro that tells A to pause until B completes and B to pause until A completes :man_facepalming:

Popping the debugger as you've done is a lot "safer" in that everything stops then everything restarts.

Me too, and I went straight to the KM/KME AppleScript dictionaries to find out. With no help there, yours is a very nifty work-round.

I also wondered about a "control macro" which ran a simple loop -- each time round it either fired macro X or the next-in-list of macros 1, 2,...n, but managing the control and sub-macros would seem to be more of a headache than a simple run of conditionals in a single place.

1 Like