The powerful, mystical Spotlight. On steroids.

March 28, 2011 · 29 comments

Your Mac comes with an extraordinary search system called Spotlight. It’s so great, so fast, so near perfection, and oh so coveted by certain unnamed Apple competitors.

How on earth can it be so good, you ask? Well, it’s hard to say. But some have speculated that it runs on only the purest tears collected from Apple’s most prized unicorns. Alas, no one has ever seen one of these creatures, which are said to be stabled in a secret location outside of Cupertino.

Until someone – most likely a Gizmodo reporter – finds that stable, I’m okay just calling it magic and using it to find stuff really fast.

Spotlight on steroids

I have to confess that until very recently, I didn’t know you could include file attributes in Spotlight searches. When I found out, it blew my mind, and I began to scour the web for tips and tricks.

This post is more or less what I found. I’m sure there’s more. Addend me in the comments.

File attributes

Your Mac stores a lot of metadata for your files. Just do ‘Get Info’ on a file and take a look at all that stuff. Much of those attributes are fair game in Spotlight searches. Simply include an attribute in a Spotlight search followed by a colon (:).

AttributeType:attribute

Here are a few common attribute types:

  • Name (i.e. the file name)
  • Kind (e.g. App, Text, PDF, Spreadsheet, Document, Image, Movie, Music, Folder, Message, and more)
  • Modified
  • Created

Special file types like music have even more. You can use things like “by” to search music by artist. Experiment; explore. You can’t hurt anything.

I find that just using the name attribute is a powerful way to narrow searches. It cuts out any hits that come from matching content. I usually remember some piece of file names, and I almost always know what kind they are. Like, say I was trying to track down my Nikon manual:

name:nikon kind:pdf

That’s probably enough to take me straight there.

Powerful date searches

The ‘Modified’ and ‘Created’ attributes can accept all kinds of dates. You can use things like:

  • Yesterday
  • Today
  • Tomorrow (kidding)
  • To search before a date, <1/1/2011
  • To search after a date, >1/1/2011
  • To search in a date range, 1/1/2011-3/13/2011

Suppose you wanted to see every text file you modified in the month of March containing the word “monkey”:

monkey kind:text modified:3/1/2011-3/31/2011

Boolean stuff and more

Like a web search field, Spotlight supports boolean operators like AND, OR, and NOT. You can also use a minus sign (-) to exclude terms. For example:

chocolate recipes -coconut

Use quotation marks to enclose phrases and parentheses to enclose search terms:

chocolate AND "peanut butter" NOT (almonds OR coconut)

Other tips

  • Check your Spotlight Preferences if you don’t see the files you expect to see when doing searches. You may be excluding that file type from Spotlight’s index.
  • Spotlight does math too. Just type an expression, and it’ll evaluate it for you right there.

Other articles on Spotlight search

{ 14 comments… read them below or add one }

Robbes March 29, 2011 at 12:58 pm

Just tried your Nikon manual example and it doesn’t work on my Mac. This is because I have a German installation – I have to use the German “art:” instead of “type:” and just leave the “name:” part out. So your example would be “art:pdf nikon” on my Mac. Looks as if those attribute searches are language-dependent.

Reply

Eddie March 29, 2011 at 1:35 pm

Thanks, Robbes. Folks with non-English installations will appreciate that tip.

Reply

Ben March 29, 2011 at 1:19 pm

Another improvement I discovered yesterday: Limit what you’re searching for in the Privacy tab in Spotlight preferences. I have the Applications folder as my highest-priority results, but it frequently causes a lot of random .jar and other files to clutter the Spotlight output. For example, if you have a lot of Adobe apps installed, they often have subfolders in the Applications folder containing the app itself along with a number of configuration files, and chances are you’re not using Spotlight to find those.

So, take them out. Add these folders in the Privacy window and it will clean up your Spotlight results tremendously.

Reply

Rainer March 30, 2011 at 5:34 am

Spotlight doesn’t index all files by default but you can add new filetypes into it. See MacRumors instructions http://guides.macrumors.com/Adding_filetypes_to_Spotlight
Very handy if you work with HTML, PHP, CSS, etc… files which have their content in plain text.

Reply

Dan March 30, 2011 at 8:50 am

Oooo

I knew spotlight could do more, but was not sure what / how

The attributetype one has got to be a killer…

Thanks

Reply

Scott March 30, 2011 at 9:57 am

You can also use spotlight as a quick calculator…just enter an equation.

Reply

tivoboy March 30, 2011 at 11:26 am

you want fast, try ALFRED. Somehow faster search in spotlight library, AND all the other things it does.

Reply

John March 30, 2011 at 12:14 pm

For Microsoft documents (Word and Excel), you can use “kind:word” and “kind:excel”

Reply

carrythebanner March 30, 2011 at 12:34 pm

The Finder also exposes these options in the standard Find window. Press the +/- buttons to add and remove criteria; holding the Option key changes the + to … for grouped criteria (all/any/none, the last option being the only way I can see to use exclusion criteria). The Other… item opens a sheet containing a searchable list of even more criteria.

Even if you’re keen to type your query in the Spotlight search field, the Finder method can be useful if you can’t recall the name of an attribute. There are also some attributes that seem to be available only in the Finder window, or at least attributes whose text equivalent I can’t readily discern (e.g. File label).

Reply

Meeee March 30, 2011 at 12:52 pm

I just use the “+” button under the search field and choose one of the dozens of modifiers. And keep a few handy for future searches by clicking on the button next to the modifier.

Reply

mauvedeity April 1, 2011 at 3:04 am

Superb work, sir! Probably the best protip I’ve had this year.

I use Spotlight a whole lot, and I didn’t know about this. Thank you for posting. I’d just like to add that it also works with the command-line tool “mdfind” – in Terminal, you can do this:

% mdfind name:nikon kind:pdf

It’ll do the search and show you the results, just the same.

Reply

fred April 1, 2011 at 6:26 pm

Don’t agree that spotlight’s magic, gave me nothing but trouble.

So I’m using quicksilver, postbox email search and the search that comes with path finder. The latter two cost money, but that way I finally did not only get rid of spotlight, but apple mail and the finder, too. Ah, the bliss.

For those using the commandline, give find, grep and ack a spin.

Reply

Patrick April 28, 2011 at 10:53 am

Well, first of all thanks for the nice tips Eddie, and, a superb blog. I found you via MacSparky.

To the ones suggesting Alfred I have to say that Alred is a whole another best. I’m a Launchbar user and if I search for a specific file and didn’t want to drill down a file manually Spotlight is still highly relevant since it has some extras to offer.

Like Eddie I just found out one could include file attributes and with TextExpander advanced searches are really just a few keystrokes away. I really can’t tell why I haven’t stumbled across such a tip years ago. But better later then never I guess.

However, I’m struggling here to find the right attributes to search for hidden and/or files which are in the system folders.

I tried several combinations of kind:system, type:system, type:invisible, etc. but I can’t get results, so I must do something wrong. If anybody has this figured out I’d love to hear about it.

Reply

Kody May 16, 2011 at 8:47 pm

Those System and hidden files and directories are not searchable via Spotlight, because to Spotlight’s engine they don’t exist. Apple may have hard-coded this when they build Spotlight, or there may be an editable property list in Spotlight’s application of directories and files to exclude beyond user preference.

Reply

Leave a Comment

{ 15 trackbacks }

Previous post:

Next post: