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.
Sounds like good middle ground between command line and GUI ...
Presumably simple globbing like *.html or *2014* etc rather than regex ?
If so, a rough start might look like this (the second osascript stage is in Applescript - I haven't figured out how to do Finder selections with JXA Paths yet)
Simply beautiful. I bought Houdahspot 4 for this functionality, to be able to search for files using wildcards because I had done it for ages on Windows using Everything.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
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.