Feature Request(?) - Duplicate condition in If-Then-Else action

At first please take a look at one If-Then-Else action of one my Macro.


I never count how many Regex match conditions in total here. Sorry for this.
But Generally when we add a new IF-Then-Else action. It looks like this:

Please see
After I add regex-condition 01:
step 01: I click +
step 02: select variable condition in dropdown menu
step 03: input var name Local__FirstName2
step 04: input Regex-condition-body
But actually Local__FirstName2 is just a small change of Local__FirstName1.
and regex-condition2 is also a small change of regex-condition1.
So in order to save keyboard-mouse-operation, you need to do a lot of copy-paste-work.
But actually you still need to press cmdc cmdv backspace arrow-key many many times.
And it's very easy to make mistake: forget change contains to matches.

But if we have a COMPLETELY NEW duplicate button on EACH condition line:


The whole process of adding new condition turn into:
step 01: duplicate similar condition to your target.
step 02: edit variable name
step 03: edit regex-condition-body
I think this work will be much easier.

You can avoid all of this, and make things much simpler to modify in the future, if you put all your regex into a variable, then use a regex search to find out if your regex is in your list of regex :).

Much harder to explain than to demonstrate:

___ Regex From List.kmmacros (11 KB)

Long screenshot hidden here

I first put some of your regex into a variable, then set (for test one) instance_Fork to a value in the list. You need to then filter instance_Fork to be regex safe, and then we search via regex to see if that expression exists in the list. In the first example, it does, so you see the 'matching' text.

Then I set it to a value not in the list and do the same tasks, and you get the 'not matching' text.

For real use, you'd have your full list of regex conditions in local_theRegex, and you wouldn't have multiple repeated actions, obviously. You'd just filter your instance_Fork to be regex safe, then a very simple if/then that acts only when there's a match.

I think this will do exactly what you want, but please test carefully—this was my first thought at a solution early on a Sunday morning :).

-rob.

2 Likes

good to know. but what if i want to add 100 conditions of other different kinds? still tricky. still need more tools.

I would just use more variables, each holding all of your sets of conditions. Then the if/then would have multiple conditions, one for each match type. Putting everything into the if/then, even if you have automatic replication doesn't strike me as the best solution: It makes the macro incredibly hard to read, as you'd have pages and pages of conditionals, and really hard to edit, as you have to scroll through all that to find the one line you want to change/remove.

(Maybe I misunderstood, maybe you're just saying 100s more conditions on that one if/then. If so, then this example is still a good way to go, because you can just, as noted below, copy the list to a real text editor that has infinite powers, make all the changes you need, then paste it back in.)

With everything in variables, you can easily edit the list at any time, with minimal scrolling—and you can even copy/paste the list into a text editor for even faster editing.

To each their own, of course, but if I were in your situation, this is how I would do it.

-rob.

1 Like

think reversely. when you only have 4, 5, or 6 similar long conditions to add. and you just don't want to create new variables for this. Duplicate button on If-Then-Else panel still make a lot difference:)

Again, it's personal preference: I would always create the variables, because (a) they're temporary, (b) editing is easier, and (c) readability is improved. But I can see why you'd find it useful to have such a button.

If my if/then has more than maybe three conditions, I'll simplify it down to variables. I just find it much easier to read and work with the macros when the if/then's aren't long and complicated.

-rob.

Could you describe the broader scope of this macro? There may be a better way to do this, perhaps using Dictionaries.

2 Likes

thanks for your reply. but you @noisneil
@griffman are all talking about another thing. you are talking about programming . but my concern is on how to add condition easierly on this panel.

I think they are trying to ask if you have considered alternatives that will be easier to adapt and expand as these lists of conditions continue to grow.

1 Like

Just a point of clarification, in your version of the macro yes, to add several long conditions you would need to "press cmdc cmdv backspace arrow-key many many times..."

but unless I misunderstand @griffman 's work, in his version, you would not be making a new variable for each condition, you would simply add the new conditions as new lines of text to the bottom of his first action. I just want to make sure you're comparing apples to apples.

Even if this is roughly the same amount of keyboard-mouse-operations, i.e.:

  1. highlight a given line, say, ^[sS][wW]/s
  2. hit return
  3. hit cmdv
  4. backspaces
  5. arrow keys etc.

If nothing else you gain A TON of readability and much easier maintenance in the future. Browsing and troubleshooting your macros currently must be difficult, or at least you must be very careful as you've said. And at least on my systems, I've always found adding a 5th, 6th, 7th, etc. switch/case condition--or really working with very large switch/case actions at all--to be a bit slow to update at times. Is it the same with very large if/then actions? :thinking:

thanks for your reply again. but you are keeping misleading the reader of this post. You all talk about Regex. But Regex is nothing here. You all want to know what i am doing on THE macro - the only one macro on earth - in detail.
but the macro can be ANY unknown macro, and the condition can be ANY kind of condition.
my question is : when i add condition on this action panel, how to get faster. And you all say don't add condition this way. i don't think you are answer this question.
i feel frustrated and really want to delete this post from the forum if i can.

We all want to help you but we're looking at what appears to be quite a ludicrous overuse of a single tool where another tool may be infinitely more efficient.

You're asking how to use a sausage to hammer nails into a wall, and we're offering you a hammer. No, I'm wrong; that implies you've told us what job you're trying to do. You're just asking "how do you use a sausage?", without any context, and we're standing here holding a bag of tools, asking "for what?".

This looks to me like a perfect example of an XY Problem.

2 Likes

Yes it’s an XY problem, but also the OP wants the feature for any if/then action, so I think they are frustrated over focusing on the macro itself.

I’m glad they posted it because I’m trying to process the solution @griffman posted :blush:

4 Likes

It's a reasonable feature request, but I do also think it would be very rare that you need this feature given that generally if all the conditions are the same, then there is probably a better way to do it, and if the conditions are all different, then it's unlikely duplicating the condition will be all that useful.

In the specific macro case, a single regex with all the conditions would be far easier to maintain and understand.

I will note down the feature request, but without a good example of a real world problem that is not better solved by less conditions rather than more copies of conditions, I'm not sure it will ever bubble up to the top of the todo list (I'm more likely to spend time on code to reorder such lists than add a Duplicate button to such lists for example).

3 Likes

OK. Interesting to see that nobody understand my problem and support my idea. Cause Every time I insert an If-Then-Else action, I am praying for Duplicate button. But what I want to say is that i post Feature-Request post only when I feel like i can't stand any more and it's really worth doing. Cause expressing in English is difficult to me.
For now, I just sort all my macros by modification time, and pick the latest macro which has an If-Then-Else action which has conditions more than one.
Please look at it:


Just three variable conditions!
Local__Targeted_Folder_A > is empty
Local__Targeted_Folder_B > is empty
Local__Targeted_Folder_C > is empty
Now think about a question. Why do these three variable names look so similar?
Cause they belong to one action of one macro.
These three conditions must have some internal connection. In most cases things is like this.
And for now we dont have duplicate button on the panel. what to do when we want to add the second and the third condition??
step-01: MOUSE -- click +
step-02: MOUSE -- click Variable Condition in dropdown menu (mouse-scrolling may needed)
step-03: MOUSE -- when you are lucky, the new variable name will be
Local__Targeted_Folder_A. so you click the end of the text input box.
step-04: KEYBOARD -- hit backspace to delete last character A.
step-05: KEYBOARD -- hit shift+A. (change varname from Local__Targeted_Folder_A to Local__Targeted_Folder_B)
step-06: MOUSE -- click contains.
step-07: MOUSE -- click is empty on dropdown menu. (mouse-scrolling may needed)
step-08: MOUSE -- click +
step-09: MOUSE -- click Variable Condition in dropdown menu (mouse-scrolling may needed)
step-10: MOUSE -- when you are lucky, the new variable name will be
Local__Targeted_Folder_B. so you click the end of the text input box.
step-11: KEYBOARD -- hit backspace to delete last character B.
step-12: KEYBOARD -- hit shift+C. (change varname from Local__Targeted_Folder_B to Local__Targeted_Folder_C)
step-13: MOUSE -- click contains.
step-14: MOUSE -- click is empty on dropdown menu. (mouse-scrolling may needed)

None of these 14 operations can be missing.

But what if we have a duplicate button on this panel??
step-1: MOUSE -- click duplicate button
step-2: MOUSE -- click the end of the text input box.
step-3: KEYBOARD -- hit backspace to delete last character A. (cause for now the varname is Local__Targeted_Folder_A)
step-4: KEYBOARD -- hit shift+B. (change varname from Local__Targeted_Folder_A to Local__Targeted_Folder_B)
step-5: MOUSE -- click duplicate button
step-6: MOUSE -- click the end of the text input box.
step-7: KEYBOARD -- hit backspace to delete last character B. (cause for now the varname is Local__Targeted_Folder_B)
step-8: KEYBOARD -- hit shift+C. (change varname from Local__Targeted_Folder_B to Local__Targeted_Folder_C)

Note we only need 8 keyboard and mouse operations for now.
But More more than this. Please see the procedure when we dont have duplicate button, in step:
step 02
step 06
step 09
step 13
you need to click one item in dropdown menu four times.

you click to open dropdown menu
->
you scroll up and down to see the item you want by your eyes
->
you move mouse cursor to the item by your hand and suffering the friction of the mouse pad
->
you click mouse button

this wastes much more time than normal keyboard-mouse-operation.

Now @cfriend @evanfuchs @griffman @peternlewis @noisneil , Let you say which is faster? which way is better?
is Reducing the number of operations not the core spirit of this automation software??
Aren't we here to save human time?

I'm not taking sides, but I read your last post, and there seems to be a bug in your sample code. If A and C contain values, but B is empty, you would end up with two consecutive commas. Or if C is the only empty one, then you end up with a terminating comma. Or if A is the only empty one, that you end up with an initial comma.

Also, you can eliminate two of your conditions by just saying all three conditions in a single condition:

If %Variable%A%%Variable%B%%Variable%C% is not empty.

As I said, it is a good suggestion, it just may not ever get implemented.

In any event, the feature request is noted, and rather than continue round in circles as folks seem to be getting frustrated, I am going to close this topic.

If there are specific other requests or anyone would like to ask about other ways of solving this issue (eg, it is possible to write an AppleScript that will duplicate a condition of a selected If Then Else action), they are welcome to do it in a new topic focussed on immediate solutions as opposed to this feature request.

3 Likes