Often I have a folder full of files, where I need to select some of them. Either based on extension or some part of their name.
What I would like to have was a macro I could trigger.
It ask for what string should be used to select files in the active finder window.
And the only these files are selected in Finder.
Then I can decide to open them, batch rename them or delete them. This should not be part of the macro.
As I see it, then I need to use AppleScript as I can not find a way to do this with Keyboard Maestro Actions.
This is a example of a folder, where I would like to select all files with "_report" in the name.
Prefix Example Notes
None any text Any name containing your literal text is returned.
/ /j\..+tolkien RegEx looks for your pattern anywhere in file name.
e/ e/.*j\..+tolkien.+ e/ is a mnemonic for exact (allows fancy patterns).
s/fi None Selects all files — s/ is a mnemonic for select.
s/fo None Selects all folders.
s/im None Selects all images.
suf/ suf/jpg Selects by suffix
The script should be easily adapted to JXA. (Yosemite-only)
I did at one time adapt this to use Keyboard Maestro's regex, but due to the very slight pauses between actions it turned out to be slower than the AppleScript ( and I don't like to wait :).
The macro is very fast, but due to the way the Finder works it slows down as the number of files in a folder increase. So selection in a folder with a thousand files will be much slower than in a folder with 500 hundred files.
Selection on my system (mid-2010 i7 MacBook Pro) in a folder of 500 files is less than 2 seconds, and with fewer files it gets close to instant.
I’ve updated the macro in post 7 to throw an error when the front Finder window is a Spotlight search or is otherwise unavailable for selecting files.
While I was at it I took a stab at selecting files in a Spotlight Search Window with System Events but couldn’t manage to select more than one row in the list-view window at once. I’ll look into this a bit more but am not optimistic about a workable solution.