Furthermore I then need to select just the 1 DOCX file in each top-level folder's hierarchy that has the latest "modified date". That's the part that seems to make this complicated.
In my example/graphic my top level folders are: "aaa" and "bbb".
Thanks. Is it possible to use a KM variable (for the path name) in the FIND (or MDFIND) command with the KM Shell Command? It doesn’t seem to work for me.
So you're trying to use a text-token in a shell script.
The text token would be %Variable%Path_Stub% NOT %Path_Stub%, but that is not the correct syntax for a shell script.
KMVAR_YourVariableName is correct.
So:
mdfind -onlyin "$KMVAR_Path_Stub"
* Use quotes to make certain spaces are correctly treated in path strings in the shell.
Keyboard Maestro understands $HOME-based paths (e.g. ~/Downloads), but you can run into issues when a path contains spaces and you pass a home-path to the shell.
You can't quote the home part of the path – you must:
~/Downloads/'my folder name with spaces'/
Or you can escape the spaces of course.
The simpler way to handle this in Keyboard Maestro is:
Shane's ASObjC script should be much faster than the other approaches, especially if you have lots of files in the folder/subfolders. Let me know if you don't see this.