[SOLVED] Check Mounted Volume From List

Instead of including 12 conditions for all my mounted volumes, is it possible to have a list with all of the names (and if I change the name of them in the future or add/remove some I can easily and quickly do this inside the list) and then use a single condition to check if any of the volumes is mounted, maybe via a variable?

Something like this I guess:

image

So I just want KM to read the list top to bottom and if none of the volumes is available, do A, otherwise do B.

Another option, since all my backup disks start with "D" followed by a number, maybe I can use that? Like:
"If any mounted drive starts with D followed by a number followed by [SPACE]-[SPACE] do A otherwise do B"

My backup disks are all:
D1 - VolumeName
D2 - VolumeName
D3 - VolumeName
etc

Whether you think option 1 is better than option 2, or vice versa, can you please show me how to achieve both so I can save those solutions to my "KM tips" document? That way I can learn a few more things that can be used in other scenarios.

Thanks!

Ok so I was looking at the For Each action and I was able to create a notification for every line in a list inside a variable, so I guess this would be the starting point?

Keyboard Maestro Export

Since you can have a regular expression in a mounted volume condition (see condition:Mounted Volume [Keyboard Maestro Wiki]) why not save yourself that long-winded hassle and use that?

1 Like

Yes, that's what I was thinking when I mentioned the second option.
I'm not familiar with Regular Expressions though...
I was looking at this page (Regular Expressions | ICU Documentation)
but it seems a bit complex for me.

How would I define: "starts with D, followed by any number, followed by SPACE-SPACE" for example?

Something along these lines as a starting point?

^[D][0-9]

This?

Check if all drives are unmounted.kmmacros (3.6 KB)

Keyboard Maestro Export

I tried it and it seems to work, the only issue I noticed is that when I run it, the engine icon stays like this for like 10-20 seconds before showing the notification:

SCR-20230519-kohl

It freezes.
Any idea what's happening?

Also, which is better for this particular scenario?

image

Try this:

^(?-i)D\d\d?\s-\s.*

And “name matching” option.

1 Like

Thanks!

Can you explain what that means, so I can understand how regular expressions work?
Thank you

Sure:

^ - what follows is a regular expression 
(?-i) - switch on case sensitivity
D - an uppercase D
\d - a single digit
\d? - possibly another single digit
\s - a white space character (literally)
- a hyphen character (literally)
\s - a white space character (literally)
.* - any sequence of characters

Hope that helps.

1 Like

Well - good luck with that. Instead of looking at the ICU docs, get yourself a regex tutorial online or a book like Jan Goyvaerts’ Regular Expressions Cookbook pub. O’Reilly.

In this context, ^ surely specifies the start of a line, no?.

@iamdannywyatt regex101 is a great test tool and learning resource. I'm on there again now..!

1 Like

No - it’s a specific KM requirement. Refer to the page in the KM wiki I linked to above.

Edit: just followed my own advice and now can’t find it, so you’re right. ^ in a regex does specify the start of the line but in the KM Select or Show a Menu action for example ^ signifies the use of a regex.

1 Like

Thanks! Saved to my notes :wink:

1 Like

Ah, that, yes I remember that. :slightly_smiling_face:

In multiline mode, yes. :wink:

1 Like

Ok so you went with my first question with the spaces. Great! Thanks!

Questions:
Why the

\d - a single digit
\d? - possibly another single digit

?

You are already thinking that it could be something like D12 for example, with 2 digits, right? If I knew for sure it would only use 1 digit, I could remove the

\d? - possibly another single digit

right?

If it wasn't important if the D was lowercase or upper case, I could remove this as well, right?

(?-i) - switch on case sensitivity

Last one:
For example if I wanted to have any character after the D, before the digit, then I would have this?

D.*\d

?

1 Like

Will do, thank you for the suggestion!

2 Likes

Weirdly I saw you say “12 conditions” originally and I just thought Danny’s drives go from D1 to D12! So if you have only 1 digit after the “D” then by all means remove the \d? bit.

Same goes for the case sensitivity, but I was just responding to your post in which all your drives all had an uppercase D.

That means “D followed by any zero or more characters followed by a digit”.

What you want is this D.\d

If you're looking for RegEx resources, here's a handy cheat sheet.

1 Like

Yes, I was just wondering if that was your thought process for that extra line so I can understand each piece you add.

Same thing. Just trying to learn how it works so I can look at this and understand other possibilities

I was actually trying to see if I could understand how to check for anything after the D, either character OR digit, any amount of times, for example D1a1 - , or D12ffk - , etc.

But no worries, I got the basics for now and will be learning a few more tricks here and there. You don't need to "waste" more time with this. I got it for now and I appreciate your help on this. The macro is now working :slight_smile:

1 Like

That looks great! Thanks!
I also started watching The Net Ninja on YouTube. I always liked his tutorials and it's super easy to follow as well.
Really appreciate the cheat sheet. Saved to my notes as well