Repeat a set of actions until I click [Continue] button

Ok, here I am again about 45 mins researching KM wiki and forum and I can't figure out how to do something that I'm sure is so simple.

I have an existing macro that works but I want to improve it by adding a few actions that would loop.

So far I've had some success by putting those actions inside an "Execute Actions Until Conditions are Met". Like this:

image

What I can't figure out how to break the loop so that it continues to whatever actions follow.

I thought that if I rename one of the buttons in the Prompt to Continue and type the same "Continue" text insdie the Until > A button: > with this name – the loop would break.

Not working. No matter which button I click it doesn't break out of the loop, it just keeps looping.

I've been using KM for years now (and pay for the upgrades) and I still get stuck with simple things. Why can't an easy to loop action be added to KM that allows you to use it out of the box? I have a feeling that to do what I need to do above, will require variables. Why make your users have to research the wiki and research the forums just to do something simple? I know I'm not alone in wishing that simple things like these get added. Every time a new update for KM comes out I hope that it has improved in ways that make this tool easier to use. Not everything should require a programmer's mindset or dexterity. Often times we resort to KM exactly because we are short with time. No? And to have to spend so much time [and energy] researching and tyring to make sense of how this tool works just makes it for a frustrating experience.

Judging by how little KM has evolved over the years I don't have any high hopes that it will become easier to use. It really is a love/hate relationship I have with this tool.

Sorry for the rant but it's almost 11pm and I'm tired and frustrated.

Thanks for any help.

To answer your immediate question: the button condition you're currently using refers to buttons in other apps, like the Open and Save buttons in a file dialog. The condition you need to make your loop work as intended is just text containing the %PromptButton% token, like so:

00%20PM

I'm sorry you've been having trouble getting KM to behave as you want. Unfortunately, no piece of software can be attuned exactly to how each user's mind works, but this forum is the next best thing to helping each other fill in the gaps in our knowledge. For what it's worth, I'm also not a programmer and also used KM for years without really taking advantage of its full potential, but once it clicked for me it became much easier to use and even more of an essential tool. Hopefully you'll manage to find a similar turning point eventually.

gglick wrote (August 2018):

The condition you need to make your loop work as intended is just text containing the %PromptButton% token, like so:

00%20PM

I've had trouble applying this to what I'm presently trying to do. I want to put the actions in the attached macro into a loop that I can exit and then have the macro manipulate the copied and pasted text in BBEdit. Adding a "Continue" button with the condition you stipulated seemed to prompt strange behavior, when the repeated steps were in both a While and an Execute Actions Until Conditions Met action.

Brave - Connections - Copy Related Words to Text File.kmmacros (14 KB)

Can someone please have a look at this and tell me how to break out of this loop and have the macro do other things in BBEdit? I remember I used to be able to set the number of repeats at the beginning, but I think this was in AppleScript rather than KM. Thanks

The macro you pasted will run the loop 16 times:

image

(Unless you hit Cancel, of course.)

Are you wanting this to run an infinite number of times, until you cancel out of the loop, replacing the existing 16x loop? Or are you wanting to add a different loop within the 16x loop? I just can't quite grasp what you're trying to accomplish.

Edit: You wrote:

Do you want it to then go back into the loop and do it all again from the top? If so, then I guess all you're trying to remove is the 16x loop?

-rob.

griffman:

The macro you pasted will run the loop 16 times: [...] (Unless you hit Cancel, of course.)

Right. I've got that much.

Are you wanting this to run an infinite number of times, until you cancel out of the loop, replacing the existing 16x loop? Or are you wanting to add a different loop within the 16x loop?

I'm sorry I didn't make myself more clear. The 16 times is the maximum imaginable, but I might never want it to run that many times. If, as I did later this afternoon, I used the macro in the form in which I sent it, I would normally cancel after between 4 and 8 times.

I just can't quite grasp what you're trying to accomplish.

I hope not to make you sorry you asked. I have recently been doing the New York Times Connections puzzle every day in a Messenger group with my two sisters and a niece. If you don't know, this puzzle (Connections - The New York Times) presents 16 words that the solver has to group into four groups of four connected words each. Some of the daily puzzles are easy and some are difficult. The solver is permitted to make three mistakes before bombing out, but I try to get them without making any mistakes at all, as many days in a row as possible. When I don't see the connections – which is often – I go to sites on the Internet (but not those with tips or the answer) to figure them out. One of these is relatedwords.io. Here's the macro that sets the tabs up for me, first creating the BBEdit windows (13" Retina MacBook Air) for playing around with the text:

Switch - Brave & Load Connections Sites- Open Two Text Foiles and Save One.kmmacros (24 KB)

You have the first steps I want to repeat automatically, with my just having to type in the search terms, in what I sent before. What I want to do after exiting the loop (which, again, will likely never run 16 times) is switch to BBEdit and process duplicate lines, putting the duplicate terms in a new window. I have these steps cut to a temporary macro, but I want to combine them with the initial ones and for that I need to be able to make the loop exit when I've gotten the related words for all of the Connections words I want to search on. Here are the additional steps:

Temp Stash Macro.kmmacros (4.6 KB)

I hope this is now sufficiently clear. Trying gglick's method gave me strange results, as I said. With a Continue button and %PromptButton%, the macro opens a new browser window, goes to the relatedwords.io homepage and searches on "chauffeur", apparently clicking on that word on the homepage. I couldn't get it to stop doing that. Thanks for any help with this.

Turn off the "Cancel Macro" option in the "Prompt..." action. Then, as the action after the "Prompt...", use an "If" action to test %PromptButton% and exit the loop if it is "Cancel".

Demo:

Repeat Cancel from Prompt Demo.kmmacros (5.2 KB)

Image

For your macro it's really personal preference as to whether you put the rest of the actions in the "otherwise..." section if the "If..." action (as in the demo), or leave "otherwise..." empty and put them below the "If..." action (but still in the loop).

Nige_S:

Turn off the "Cancel Macro" option in the "Prompt..." action. Then, as the action after the "Prompt...", use an "If" action to test %PromptButton% and exit the loop if it is "Cancel".

Many thanks for this. I modified the loop accordingly, added the extra steps and then tested it. Oddly, the text selection at the website worked the first time through but not the second. I lengthened one or more of the pauses at the location concerned and then it also ran the second and subsequent times. I don't know why it worked the first time and not the second, but then what do I know.

Demo:

Repeat Cancel from Prompt Demo.kmmacros (5.2 KB)

This helped, thanks.

For your macro it's really personal preference as to whether you put the rest of the actions in the "otherwise..." section [o]f the "If..." action (as in the demo), or leave "otherwise..." empty and put them below the "If..." action (but still in the loop).

I did it as in the demo, but now did it the other way as an exercise and discovered I preferred the way you'd done it. It somehow doesn't seem nice to leave "otherwise..." empty. Thanks again.

Hard-coded pauses can be problematic, especially for things like web sites -- they often have to be either far longer than ever necessary or run the risk of breaking because of a laggy connection, interrupted page load, or similar. See if there's a state change you can use in a "Pause Until..." action instead.

Make a "Comment" action, rename it "Do Nothing", save it as a Favourite. Drop that into any "otherwise" clause that you want to leave "empty" and it'll indicate that the clause is deliberately empty and not just forgotten about.

I named mine "You left this empty on purpose, remember?!" :slight_smile:

-rob.

1 Like

Don't tell @DanThomas, he'll be onto you about all those extra bytes :wink:

1 Like

I know you were kidding, but it's just like any other kind of optimization - you reach a point of diminishing returns when you start worrying about all the little crap. Solve the low-hanging fruit, then forget about it.

I'll do that, thanks – also because it's a pain trying to figure out exactly how long what you call a hard-coded pause should be.

Make a "Comment" action, rename it "Do Nothing", save it as a Favourite. Drop that into any "otherwise" clause that you want to leave "empty" and it'll indicate that the clause is deliberately empty and not just forgotten about.

I wasn't aware of the Favorites action group until now, but I'll start hauling frequently used actions into it from now on. Thanks again, and sorry I'm not consolidating my present replies. I've been handling them consecutively from my Mail inbox and there are a couple of different forum threads, but I now notice I can see the first part of the thread title under "Subject" and so I'll know what's what in the future and won't reply to everything in separate posts.