Since I upgraded to macOS High Sierra, I found that Spotlight search for filenames doesn’t work as good as it did in previous macOS versions. I submitted a bug report to Apple some months ago, but I don’t expect a reply or fix soon…
So Keyboard Maestro to the rescue! (i hope)
In attachment I made a selection of 23 files: example files.zip (12.9 KB)
I made them empty (zero byte) files because only the filename is important here.
Let’s search for files with venti and system in the filename:
This brings up all 23 files as expected. But it’s very cumbersome compared to simply typing it in the searchbox. So I want to automate this using Keyboard Maestro.
Whenever I type a search query in the search box and hit CTRL+ENTER, it should trigger the KM Macro. I can split the string into different variables, and let KM add a “name contains” row in the finder window for each variable. But that involves a lot of simulated clicks.
Any ideas for a better solution, with less GUI scripting?
One idea is to use the powerful mdfind in terminal, but I’m not sure if and how search results can be displayed in the finder window.
Have you tried typing this in the Search box: name:venti name:system
I have found that Spotlight Search in the Finder (even on Sierra) can become confused if you don't enter that search criteria as it expects.
In addition to that, I usually just enter one search term, like name:venti, then arrow down to select the proposed term; then do the same for the second term. A bit more work, but it provides better results.
Thanks for the suggestions, but none of these provide the expected results. In fact, I’m quite familiar with the Spotlight syntax and different ways of inputting search queries. Consider myself a Spotlight junkie ;).
I’m not sure about the exact cause and in which macOS version it was introduced, but Spotlight on High Sierra seems to have trouble with some (but not all) files containing dashes. Replacing every dash in the filenames with underscores will provide correct search results using the regular search box input.
Unfortunately, we have used a file naming conventions using dashes for many years. The only way to have reliable search results is, afaik, to use “name contains”. Either in Finder (with a whole lot of clicking) or mdfind (which serves the results in terminal).
What I’m hoping for is a fast, reliable KM macro for serving search results of a “name contains” query in a finder window.
Yeah, should have mentioned it. It’s more of a macOS support topic, but my hopes for getting this fixed by Apple aren’t too high. Judging from many long-standing issues I read online, it seems Spotlight isn’t a very big priority for Apple. Which is too bad because it’s such a powerful feature. It’s also the main reason we chose a mac server above a windows server for our workgroup, for blazing fast indexed search on the network drive .