Spotlight and word search

When you type in your search terms, Spotlight looks for even a partial match at the beginning of a word. So, when you search for phon you’ll find phone, phony, and phonatory, but not symphony.

What’s tricky is that Spotlight’s definition of a “word” differs from yours. If there’s a capital letter in the middle of a file name, as in cellPhone, Spotlight sees the name as two words, cell and Phone, so it will include this filename in your results.

Punctuation and non-alphabetic characters (like numbers or bullets) serve as word delimiters, too. So, a switch between alphabetic and numeric characters also defines a new word: "Chapter4ANewHope" is five words as far as Spotlight is concerned—but the third is "AN" and the fourth is "ew."

This means that if you name multi-word files without spaces, as so many of us do, you can still easily search for any of the words in its name. Or, say you want to open TextEdit using the Spotlight menu’s capability of launching a found application. You can type t e to get TextEdit and then press Return to launch it.

# Searching for an exact phrase

Because the default behavior is to search for each word (an AND search), in order to search for the actual phrase, you need to escape your quotes like so:

mdfind \"I love Apple\" -onlyin ~/Documents

Without escaping them, I don't think the quotes actually get passed to the mdfind command, they're just interpreted by your shell to say that I love Apple is a single argument. With the backslash-escaping, the argument then includes the quote characters.

An alternative is to use double quotes can also be placed inside single quotes:

mdfind '"exact phrase"'

This would search only in the contents:

mdfind 'kMDItemTextContent=="*exact phrase*"'

# See also

All words passed in a query string to mdfind are implicitly ANDed together. That is, "invoice apress" means both words must appear. Spotlight allows other Boolean operators as well:

Here are some commonly used spotlight attributes that you can use with mdfind:

Spotlight is a system-wide desktop search feature of Apple's OS X and iOS operating systems - wikipedia

Site Owned by: Donaldr Noyes