Accessing Finder submenus (File->Find->Name->Contains)

I'd like to create a macro that puts my cursor right into the Finder/Spotlight field outlined in blue in the screenshot below, so that I can search for all files whose name contains whatever text string I choose to enter. I.e., I want it to call up this particular search template. I can use Select to access Finder->Find, but I don't know if KM has a built-in command that lets me go deeper.

If you're doing this manually from within Finder, you need to click the "+" button to right of Save (at the window's RHS; here it's already been clicked, so it displays as a "-"). That opens the advanced search options you see below. Within the latter, you need to change the left-most option to "Name", and then change the following option to "contains".

I did find, among Peter Lewis's set of example macros, one called "Finder Find by Name", but that doesn't work on my system (and, in addition, likely doesn't incorporate the "Contains" modifier).

I don't think KM has a built-in command to explicitly help with this use-case, but I can think of a way to use KM to help automate this. Once you've set up a search the way you want like this, try saving it and then opening the resulting saved search query with KM. If you save it in the default location with the default name, you should even be able to use this sample macro as-is:

Activate Finder Saved Search.kmmacros (1.2 KB)
00 AM

One admitted downside of this method is that it always opens a new Finder window, so depending on your preferred workflow that may not be ideal, but even with that possible drawback this seems like a much faster and more certain way of accomplishing your goal.

That works if I want to repeatedly do a specific search (say, for all files whose name contains “energy”). But note that, in my screenshot, I left the search box blank, because I want the macro to call up that blank box (with its associated configurations), at which point I can enter whatever specific text string I choose. I.e., I don’t want the macro to call up a specific search, I want it to call up a search template. And the Mac doesn’t seem to allow me to save search templates (though aftermarket programs, like HoudaSpot [which I don’t have] do).

To better clarify this in my opening post, I’ve changed “I can search for all files whose name contains a certain text string” to “I can search for all files whose name contains whatever text string I choose to enter” and added the term search template.

Here’s a macro that may solve your problem, or at least give you some ideas. It operates at one higher level allowing you to enter the Spotlight search terms, then executing either a std Spotlight Search or a Finder Spotlight search.

See Spotlight General Purpose Search (macOS)


Thanks, that’s great! It effectively gives me what I need, using a different route. I did notice a bug in the macro; I’ll create a post describing it on the macro’s thread.

Whether or not it’s better for this situation, it may be worth knowing that the standard Spotlight search field available from the menu bar supports many boolean search operators. In this case, entering into Spotlight name:SomeText will search for files with SomeText in the file name.

As a simple example, I often have to search for text within PDFs, so I have a Keyboard Maestro text replacement macro whereby if I type kdp it converts that to kind:pdf so I can use some search term and that search operator to look for my desired content only within PDFs.

Those boolean search operators and many more are discussed in this old (circa 2005) but still informative document:

The built-in Mac Help has plenty of similar tips as well. In 10.11, searching for Spotlight allowed me to narrow the results to a Help page titled “Narrow The Scope of Your Searches.” It looks like a similar page is still in place for 10.13.


Thanks! Nice link.

Hey @theorist,

It can be done, although like @JMichaelTX shows later I would normally use the search field and Spotlight's text-tags.

I have a number of text expansions set up specifically for that purpose like:

na<space>	==	name:
fn<space>	==	filename:
kfl			==	kind:folder
kf			==	kind:file 

I also have all known Spotlight kinds, keywords, and raw syntax codes in Typinator sets, so I can find them quickly with Quick Search.

To drive the Spotlight UI in the Finder you'll have to do something like this with AppleScript.

Keyboard Maestro 8.2d1 “Finder ⇢ Activate Spotlight UI ⇢ Find by Name Contains v1.00” Macro

Finder ⇢ Activate Spotlight UI ⇢ Find by Name Contains v1.00.kmmacros (7.6 KB)

This may or may not work on your system; UI-Scripting is finicky and can be disrupted by changes in the UI made by Apple or by the user (e.g. the user changes the Finder toolbar or some such).

I've tested this only on my own macOS 10.12.6 (Sierra) system.

This method should scale to adding many more criteria, but I can't say for certain without testing.

Personally I use HoudahSpot when I want to get fancy.


1 Like

2018/03/16 01:00 CST — Macro in post #8 improved a bit.


Chris, why use UI scripting to invoke Spotlight search in the Finder?
There is a shortcut for this, which can be set/changes in System Preferences > Keyboard.
It works reliably. That is what I use in my above macro.

Hey Jim,

It works with the frontmost window in the Finder, instead of opening a new one.