How Do I use KM Variables with a "find" Shell Script?

Hello, I'm trying to make a macro that allows me to search a mounted volume for a specific filetype and do one set of actions if it exists, and another if it does not. The mounted volume will be set as a variable so I'll know what it is, it just will change. I have a shell script that can find the filetype, but I don't know how to set the search location as a variable and then execute an action based on whether or not it found said filetype.

ie: find /Volumes/EXTERNAL_DRIVE_1 -iname "*.slv"

I want the "/Volumes/EXTERNAL_DRIVE_1" to be a variable so the search location automatically gets updated when I update the EXTERAL_DRIVE_variable.

I'm a beginner with programming, but am learning. Any help is greatly appreciated. Also, if there's a better way to achieve this, I'm also open to suggestions.

Here's an example shell script I have used to get you started:

find "$KMVAR_GLF__FolderToSearch" -maxdepth 1 -name "*$KMVAR_GLF__KeyWord*"

For more info on using KM variables in shell scripts, see:
Execute a Shell Script action -- Using KM Variables.

Thank you very much. With that I was able to achieve what I wanted.

I hope you don't mind that I have revised your topic title to better reflect the question you have asked.

FROM:
Search variable location for specific filetype + execute if/else?

TO:
How Do I use KM Variables with a "find" Shell Script?

This will greatly help you attract more experienced users to help solve your problem, and will help future readers find your question, and the solution.

To answer you second question, just set the output of the Execute a Shell Script action to a KM Variable, let's say "Local__FileList".

Then use a If Then Else action to test the KM Variable "Local__FileList" for being "empty".

No issues with renaming topic title. Thanks.

And re: variable with shell script, that's exactly what I did and it works perfectly and quite fast as well.

1 Like