Question About Conditions

I've been using the conditional actions and realized, there are some differences between them that confuse me. I have 1 or 2 main questions and a few minor ones. If this has been asked before, or it's addressed some where in the Forum or manual that I missed, I'm happy to research it myself if someone points me in the right direction. Thanks...

My questions are about "if all else," "pause until," "text in a window," "insert text," "display text briefly and large" and (even though there are no conditions with this action,) "Prompt For User Input."

1
My main question: When does the action stop the macro completely...And: Do some of the actions stop the macro partially? If so, to what extent.

'Prompt For User Input' stops the macro to a dead halt (and cancels it, assuming you leave the cancel macro boxes checked). That's clear. The 'display text briefly' and 'large' actions do not stop the macro. That's also clear.

What about display text in a window? That action displays text in a window with an OK button. Does this mean, the macro doesn't continue forward until/unless the OK button is pressed? I assumed this was true but then, I wrote some macros where (i'm fairly certain but not positive) I had some macros that continued even though that OK button had not been enabled. Is this a grey area? Or does the macro stop as long as that OK button isn't pressed. If someone knows the answer, I'd be appreciative.

Q 2
What is the effect of a pause action placed above (or before) "Pause Until" but after the action that triggers the 'Pause Until' action. I wrote a macro that needed a piece of text highlighted. A 'Pause Until action' stopped the macro until the piece of text was highlighted in the action that came before it. (The condition was "escape is down"). Once the l text was highlighted and the user pressed Esc, Pause-Until would permit the macro to continue. I tried using Prompt for User Input as my first action but later changed it, to simplify. I wound up using Display text followed by Pause-Until.

It took a long time to get it to work. I tried placing a short pause between the two actions. That's when it got really confusing. I realized, the Pause that I squeezed between the two actions may have mucked it up The condition that triggered the change - a pressed escape key - may not have been enabled by the time the second action was triggered (due to the Pause). In other words, the pause action may have rendered the second action useless. But I'm not sure. Adding the pause definitely didn't help. In the end, I removed all pauses and this worked the best.

My tentative conclusion: While Pauses usually help macros, this is one place in a macro where a Pause can damage it. Has anyone had experience with this?

Those are my main questions. I have a few minor ones that aren't as important but do come up, here and there. If anyone happens to know the answer, I'd be appreciative.

Q 3
Is there a difference between the 'If-then' part of 'If-then-else' and 'pause until.' On the surface, it seems to be very similar. With each, a condition triggers a change. As I write this out, I'm realizing, 'If-then' is broader. The change in 'Pause-until' is restricted to, going from a pause to something else, under certain conditions. WIth 'If-Then,' there are other possible changes. Is that the only difference?

Q 4
A related question. Sometimes, I'll throw in pause .01 in the 'else' part of if-then-else. I do this when I just want an If-Then action. and I'm not interested in the 'else' part. Does that action work as an If-Then action and if so, can the else part be left blank?

Q 5
A final minutia question. It's about the 'While' action. The While action reads,

"While all of (any of, not all of, or none of) the following are true, execute the following actions."

The first time I played with that action, based on the wording, I assumed I understood it. Now I'm not sure. If my condition was a pressed escape key and I had 3 minutes of actions lined up - to be executed as soon as Escape was pressed - I assumed, the actions would only fire while the escape key was down.

So: If the key was pressed for a tenth of a second, I figured, my actions would execute for 1/10th of a second. Then, they would stop. But when I tried the action, the condition seemed to trigger actions after the trigger was disabled. Which is why I'm not sure what it does. Any clarification re this issue would be appreciated.

Thanks for any help!

Most actions stop the macro.

The primary exception is any UI actions (like typing keystrokes, including the ⌘V for Paste) because these are added to the system event queue and will be processed by the system when it is good and ready, and so there is no way to know how long to wait - Keyboard Maestro does include a short wait generally).

Another set are those that activate some facility (like the Application Switcher) or display some sort of notification - the display will remain, but the macro will continue on.

Usually you can tell if an action will wait an indefinite amount of time because the action will have a timeout facility.

No, Display Text/Image/Clipboard (in any of its forms) does not wait.

I am having a hard time understanding that question, but there are lots of cases where you want a Pause on either side of a Pause Until.

Basically, Pause Until is going to wait for a condition to become true (say a process to have completed).

Imagine a case where your first action is to open a web browser window with a URL. And that web browser window will start with a title of "Loading", which will always last somewhere between 5 and 15 seconds, and once it has finished the title will change to something else, and then within a second after that the answer will be displayed.

Ok, so you could just user Pause 20 seconds. Time enough for the window to open, the loading to happen, and the answer to be displayed. But you're wasting up to 10 seconds every time.

So instead, you want Pause Until window title is not “Loading”. Fine. But the window title is not “Loading” at the start, until the web window opens and gets far enough. So you add a Pause 5 Seconds at the start.

But also, the process has not entirely completed when it finishes loading, so you add a Pause 1 Second at the end:

  • Pause 5 Seconds -- wait until the web page starts loading
  • Pause until title is not “Loading” -- wait while loading
  • Pause 1 Second -- wait for answer

Now you will wait only long enough to get the answer.

The issue, if I am understanding you, is that you paused while you pressed Escape and thus missed it. The issue here is not the problem with the Pause, but that you are using a Condition to detect an Event. Try to remember that basically Triggers should be used for Events, Conditions should be used for State.

In this case, the solution is to use a Trigger to detect the Escape key.

Macro 1:

  • Set variable “Escape Pressed” to 0
  • Enable “Macro 2”
  • Do stuff
  • Pause until variable “Escape Pressed” is 1

Macro 2 (initially disabled)
Trigger hot key (or USB Device Key) on Escape pressed

  • Set Variable “Escape Pressed” to 1
  • Disable Macro “Macro 2”

Whenever possible, use a trigger to detect an event, rather than a condition.

Even without the pause, if you tap the escape key fast enough, then the loop could miss it (its less likely, obviously, but it could happen).

Honestly, I'm not sure how to answer this.

Conditions determine whether a state is currently true or not.

Pause Until pauses until the condition is true. It is essentially identical to:

  • Repeat until condition is true
    • Do nothing

The condition is evaluated over and over until the entire condition is true.

If Then Else evaluates the condition and executes one or other branch of the action.

The condition is only evaluated once (once for each time the If Then Else action is executed anyway).

Yes, just leave either side of the If Then Else action blank if you don't want it to do anything.

No pause is required.

You can add a Comment action “Do Nothing” if you want.

A while loop evaluates the condition. If it is false, then the while loop is done, and the next action after the while loop will be executed. If it is true, then the actions within the while loop are executed. After that the whole process starts again. And again. And again. Until the condition evaluates as false.

No.

All the actions will execute, or none of them. Once they are executing, they will all execute to the end. Only then will the condition be evaluated the next time. Similarly, if the condition is false to start with, none of the actions will ever execute, and the macro will continue on after the while action. Only if the while action is itself executed again while the condition be reevaluated and the actions possibly executed.

1 Like

Peter wrote: No, Display Text/Image/Clipboard (in any of its forms) does not wait.

Thank you! I figured that was the case. What threw me was the OK button in the display text window. I associate OK buttons with stopping the macro but it doesn't do that here, obviously....

Peter wrote: I am having a hard time understanding that question, but there are lots of cases where you want a Pause on either side of a Pause Until.

Thx for your web page example. I do sometimes use Pause Until in that way. But I think the issue I'm bringing up is slightly different. I'll clarify: The macro I sent you - focusing on the UI - has the following code in it:

file:///Users/house/Desktop/Screen%20Shot%202019-08-02%20at%2011.42.08%20AM.png

When the macro reaches those two actions, it waits for me to highlight the 'X' in the shell script. The reason it waits is that Pause Until uses a L mouse button condition and (as the User) I trigger Pause Until because I press down on the L mouse button when I highlight the 'X.' In other words, when I highlight the 'X' - and press the L mouse button - the macro immediately inserts text (the next action, not shown above). The point I was trying to make is simple enough: The Pause Until action (above) triggers the action after it (Insert text) when I highlight (again, because I use the L mouse Button.) But: If I place a separate, standalone Pause action before Pause Until, the macro stops working. When I remove the standalone Pause action, the macro starts working again. I just figured, an additional Pause before Pause Until prevents its execution, at least, in my macro. Am I right?

Peter wrote: The condition is only evaluated once (once for each time the If Then Else action is executed anyway).

That was useful, thanks for the explanation. The difference, if I'm getting you: One evaluates over and over while the other evaluates once.

Peter wrote: Yes, just leave either side of the If Then Else action blank if you don't want it to do anything.

Thanks...that helps as well.

Peter wrote: A while loop evaluates the condition. If it is false, then the while loop is done, and the next action after the while loop will be executed. If it is true, then the actions within the while loop are executed. After that the whole process starts again. And again. And again. Until the condition evaluates as false.

Wow. I totally misperceived what While does. That helps a lot. Thanks again....

1 Like

Correction: Here's the png of the two actions referred to, in my reply to your explanation. It didn't open when I posted it above. Five paragraphs down, in my reply. Thanks...

08%20AM

Just a little formatting tip:

Instead of the “Peter wrote: <text in italics>” thingy you can just select the text you want to quote (Peter’s text) and click the “Quote pop-up that appears there right above the selection (at least with Safari it appears there). Then, assuming your cursor in the edit field is on the correct position, the selected text will be pasted as a proper quote there. (Including the pointer to the author etc.)

1 Like

Thanks for the tip... (I knew that. I like italics)

Peter: I believe you misunderstood one point re Pause Until. I opened the png's, clarified in my reply to you above and retested the Pause Until action. I figured out the problem.

What I say in my original post is true. (To use the macro I sent as an example), when I was writing it, for some reason, the macro wouldn't execute the Pause Until action. As I mentioned, I added a brief pause between the display text action - which, for this macro, prompts the user to highlight a portion of the text thus pressing down on the L mouse button (which creates the condition that triggers the next action, Pause Until). Pause Until executes immediately after the user highlights the text because the L mouse button is used to highlight, which as I mentioned, creates the condition required for the Pause Until to execute.

Certainly, if I place a long (separate standalone) pause action (3, 4 seconds) immediately before Pause Until, Pause Until doesn't execute. In fact, if I place a one second pause before Pause Until and I brace myself to highlight the text that needs to be highlighted as quickly as is feasible - and manage to Press the L Mouse button in less than a second - Pause Until doesn't execute.

While I'm not versatile with Objective C, here's my guess: During the two tests above, the L mouse button condition was never presented (so to speak) to the Pause Until action. The pause was.

I do think this is an important point for people to know because the general wisdom is that pauses between actions will usually facilitate a macro's efficiency (with certain exception that you mention in your reply above). Pause Until, seems to me, is a clearcut exception for the reasons described above. Thanks.

By the way, when you refer to my use of the Escape key as a condition, if I may say, that confuses just a little only because I nixed that. I think I sent an updated macro. But no matter, the important pieces of the puzzle are in the three actions below. Importantly, the act of highlighting the text - thus pressing the L mouse button - is the condition that triggers Pause Until.

*10%20PM *

The Display Text Briefly action does not cause the mouse button to be pressed.

I would guess that the mouse button was pressed by you prior to executing this action (perhaps as some part of the trigger, or for whatever other reason).

But the Display Text Briefly action definitely does not press the mouse button.

Of course the the display text briefly action doesn't cause a button to be pressed. I suppose I can see how you might have read that into what I wrote. Kindly re-read (I'll embolden the points that should have emphasis)

...the display text action.. prompts the user to highlight a portion of the text

"...thus pressing down on the L mouse button," meaning, the user responds to the prompt and presses down on the L mouse button. I originally used the tried and true 'Prompt For User Input' action but decided (since the was going to be used for batch creating), I wanted to simplify and streamline. And so, I placed the (highlight) prompt in a Display Text action and then placed a Pause Until action after it.

It eventually turned out well. The macroworks. As soon as the user (responds to the prompt) and highlights text, using the L mouse button, the next action is triggered. My original point is simple enough. The macro had problems when I inserted a Pause action between the prompt and Pause Until for the reasons explained above. I just wanted to point that out. That's all.