Action that selects first file in Finder window that contains a certain string?

I have a macro that opens a certain Finder folder, and I'd like that macro to also then select – not open, just select – the first file in said folder that includes the string "***" in its file name. (Note that the files are sorted alphabetically.)

Is there any relatively straightforward way to do this? Thanks!

This should do it:

Select File Containing String in Current Folder.kmmacros (21 KB)

Macro screenshot

1 Like

Thank you, @noisneil! I will be sure to try this out when I'm home tonight.

One other related question for you: What if you alternatively wanted to select the child folder (but not file) of your current folder that is last alphabetically?

For example, if you were in a folder that has the child folders "2021," "2022," and "2023," and also the files "2024 Plan.xlsx" and "2025 Proposal.docx," the macro would know to select the "2023" folder.

To adjust the previous macro, you'd check the file type, like so:

Select Subfolder Containing String in Parent Directory.kmmacros (22 KB)

Macro screenshot

Of course, if the folder name is literally 2023, it's as simple as:

Select Subfolder by Name in Parent Directory.kmmacros (20 KB)

Macro screenshot

1 Like

Thanks, @noisneil! This works perfectly.

1 Like

You mean first not last.

Why the summary? Have I missed something?