[SOLVED] If Then > Variable contains X OR Y values

When using the IF THEN action, is it possible to add an "OR" condition instead of adding multiple conditions separately?

For example I want to check if a variable contains X or Y.
I tried adding the vertical bar | as it seems to be used sometimes, but it doesn't seem to work

So for example here I would be searching for the words "dmg" OR "Spire"

Instead of adding them separately like this:

Try this. If I recall, this does what you want.


1 Like

Yes it did, thanks!
What's the difference between using "Contains" and "Matches"?
I never really understood this.

Also, would this be possible using "AND"? If so, what's the symbol for "AND"?
Sometimes in certain scenarios, adding multiple separate conditions is too much work and time consuming

From the docs your choices are defined as:

* exists.
* does not exist.
* is empty.
* is not empty.
* is (case insensitively) a specified string.
* is not (case insensitively) a specified string.
* contains (case insensitively) a specified string.
* does not contain (case insensitively) a specified string.
* starts with (case insensitively) a specified string. (v8+)
* ends with (case insensitively) a specified string. (v8+)
* is alphabetically before a specified string. (v7.2+)
* is alphabetically after a specified string. (v7.2+)
* matches a specified [regular expression](https://wiki.keyboardmaestro.com/Regular_Expressions).
* does not match a specified [regular expression](https://wiki.keyboardmaestro.com/Regular_Expressions).
* is numerically less than a specified calculation. (v8+)
* is numerically less than or equal to a specified calculation. (v8+)
* is numerically equal to a specified calculation. (v8+)
* is numerically greater than or equal to a specified calculation. (v8+)
* is numerically greater than a specified calculation. (v8+)
* is numerically not equal to a specified calculation. (v8+)

I think that means "contains" is strictly a string while "matches" is a regex. Indeed, I think regex's support "AND" matching. It's a complex topic. The symbology for "AND" isn't as simple as "OR". Let me see if I can dig it up for you. Hang on.

Here's the syntax for "AND":


Regex is roughly as big a topic as AppleScript. I think I understand about 10% of AppleScript, but probably 25% of Regex.


Thanks for that!

So from what I understand, if I use the | while using "contains", it will read everything as regular text. So it would read "see if it finds the text dmg|Spire".
If I change to "matches", then it read the | and OR, like "see if it finds dmg OR Spire". Right?

I just tested the regex for the AND option anti works.
Thank you so much. Gonna save it here and even create a snippet, because I think it's better than using multiple conditions in certain scenarios

Well you're way ahead of me anyway.
I keep saving notes on my computer so I can learn a bit more about those.
Learning KM is already a great challenge for me and I put a lot of effort into it, but then learning a few simpler things to complement it (AS, RegEx, Shell) is always a plus

Correct. It will not interpret any symbols like "|" to have any special meaning.

Yes, and to be honest, "OR" is far more useful than "AND" in my experience for conditions on any text variable. It's rare that I need an "AND." But when I do need an AND, I sometimes just use multiple conditions because it's quicker than looking up the regex syntax.

AppleScript, Regex, and Shell are such big topics, that it might even make sense for the "Questions & Suggestions" forum on this website to be broken up into four forums:

  • Q&A for Keyboard Maestro features
  • Q&A for AppleScript usage in KM
  • Q&A for Regex usage in KM
  • Q&A for Shell usage in KM

I mean, after all, they have a topic on this website called "Plug in Actions" which sees a new topic only once per month.

If I save it as a snippet, then it's fast. I think it depends on each scenario.
One advantage I see of using the RegEx for either OR or AND is to create nested conditions, which I wish KM would allow, the way Finder and Hazel allow. This is super useful, so now with RegEx it can be expanded to that.

Agree 100%.
Those 3 are great "extensions" to KM and having separate forums would maybe help having everything organized.