Spotlight's Secret Search Syntax


Recommended Posts

:o

With the release of Mac OS X 10.5, Leopard, Apple has greatly improved its search technology, called Spotlight. Introduced with the previous version of Mac OS X (Tiger), Spotlight was both brilliant and stunted; brilliant because it can work so well in certain situations, but stunted because it was so limited. It didn't offer Boolean searches (AND, NOT, OR), which meant all your searches were, like Google searches, based on every word you entered. So if you typed King and Lear, you'd find anything with both words, but not with King or Lear alone. And there was no way to find a file containing Kind and NOT Lear. All that's changed.

Boolean searches, however, are just the tip of the iceberg. Tiger had a couple of operators you could use with keywords, that most people didn't know about. They were the kind: and date: keywords. You could type, say, kind:pdf to find PDF files; or kind:music to narrow a spotlight search down to music files. And you could use date:today to find files modified today, and date:tomorrow to find appointments scheduled for tomorrow. (You can use both these keywords in the Spotlight menu, or in the Finder's Search field.)

c:These two keywords still exist in Leopard, but are greatly expanded. Let me begin with the date: keyword, since it's the simpler one. To start with, Apple has added operators that you can use with this keyword: they are >, <, and -.

Here are some examples:

date:>1/1/07 will find any file modified after January 1, 2007. (The dates you enter must correspond to the short date format you have set in your International preferences.)

date:<12/31/07 will find any file modified before December 31, 2007.

date:1/1/07-12/31/07 will find files modified between those two dates.

But things get interesting when you look at the kind: keyword. Apple has expanded this to dozens of new kinds, and made it potentially limitless. There is no list of kinds, but you can get an idea by doing the following. In the Finder, type the letter "a" in the search field. Choose List View (click the List view icon, or press Command-2). Then click the Kind column to sort by kind in alphabetical order. You'll see a wide range of kinds: from Alias and Application to ZIP Archive, by way of MP3 Audio Files, Folders, JPEG Images and much more. Now try a Spotlight search, either from the Spotlight menu or the Finder: type, say, kind:word, if you have Microsoft Word documents on your Mac; if not, try kind:text. The former will show you all your word documents, and the latter will show you all your text files, at least those created by TextEdit and some other applications.

This is especially useful when tracking down files you made with specific applications. For example, I'm writing this article in BBEdit; I can search for all BBEdit files by typing kind:bb (you don't always need to type out the entire kind to get hits; two or three letters may be enough).

Well, you may think that's powerful, but you haven't seen anything yet. In addition to these expanded operators, Spotlight now has a limitless set of other operators. Not only are there kind: and date: keywords, but there are dozens of new keywords. None of this is documented yet, but you can get a glimpse of what's available by selecting the Other attribute in the Finder's search bar, or by checking the following file:

/System/Library/Frameworks/CoreServices.framework/Frameworks /Metadata.framework/Resources/English.lproj/schema.string

The former gives you names and explanations, and the latter shows you exactly how to type the operators. For example, to use Audio Bit Rate, you'll see in the latter file that you have to type either audiobitrate: or bitrate:. Here are some examples of the new operators:

Find a file by searching for the person who created it (in programs that store this information) by typing author:. For example, I'll find files I've created with author:kirk. For now, the only programs I have that come up are Word, Pages, Mail and iChat (chat logs). There are also some PDF's I've created from Word or Pages files. (You can also use from:, with: or by: to find the same information.)

Find files created using the AAC codec with codeaac. This finds both music and video files.

Find files with comments using the comment: operator. This applies to comments made to iTunes files as to Spotlight comments added in the Finder; other programs may also support this.

Find files with an audio bit rate of 32 kpbs by typing audiobitrate:32, or bitrate:32.

Find music files where Bach is listed as composer: composer:bach.

Find pictures taken at an ISO speed of 400 by typing iso:400; find photos taken at an ISO speed higher than that by typing iso:>400.

I'll stop here, but you can see that the possibilities are quite extensive. In addition, third party programs can add their own attributes that can be searched. One way to find what they can do is to take a file and run the mdls command in it in Terminal (mdls <filename>). This will display all the file's metadata, and will allow you to discover which attributes it is using. You'll also see this information in the Finder, when you choose the Other search attribute as explained above.

As yet, Apple hasn't documented this, so let's hope they do so soon with a complete list containing explanations. (For some of these operators it's not clear exactly how to use them; however, if you have files that they can find, some trial and error should help you discover the answer.) These operators are likely not something you'll use daily, but when you're trying to find that lost file on your Mac, or simply trying to sort a group of files, will come in handy.

http://www.mcelhearn.com/article.php?story=20071114093450231

http://www.macosxhints.com/article.php?sto...071115150413809

:wub:

There's many more undiscovered. Photographers: in addition to iso:, try aperture: and whitebalance:

Link to comment
Share on other sites

So powerful, in fact, that I still prefer to use it the old-fashioned way: just type in a general description of what I'm looking for.

Link to comment
Share on other sites

incredible!

good to know you can take advantage of all those under-the-hood functions :)

makes it scream :D

Glassed Silver:mac

Link to comment
Share on other sites

So how does the "new and improved" Spotlight compare to the search functionality in Vista?

Well, if the non-"new and improved" search was already better than Vistas search...

Link to comment
Share on other sites

So how does the "new and improved" Spotlight compare to the search functionality in Vista?

Vista's search was better than the original implementation of Spotlight because it could act like an application launcher, among other things. The new version of Spotlight brings it up to par, as now they both act as application launcher, can both search networks, do Boolean searches, etc. They both work well.

Link to comment
Share on other sites

Vista's search was better than the original implementation of Spotlight because it could act like an application launcher, among other things. The new version of Spotlight brings it up to par, as now they both act as application launcher, can both search networks, do Boolean searches, etc. They both work well.

Spotlight always functioned as an app launcher as well, no?

Am I forgetting something?

Link to comment
Share on other sites

I've been trying out some of the AND, OR delimiters in Spotlight & you can make some really powerful searches.

Here are some handy ones I found when wanting to search by name only in Spotlight's menu bar search:

name:filename - Search by name (single word)

name:"multiword filename" - Search by name (more than one word)

And this is pretty handy too if you add Spotlight comments to files

comment: - Search Spotlight comments

Also a couple of keyboard shortcuts

⌘F - Find by contents

⌘⇧F - Find by name

Link to comment
Share on other sites

i think it was so slow before that it wasnt practical to be an application launcher

True.

I had to use Launchbar before Leopard - so yes, the speed factor was indeed an issue.

Link to comment
Share on other sites

It wont work. Why? Because in the Spotlight menu the focus is never taken out of the text box. Click on any item in the menu and it executes instead of gaining focus. Because focus is always on the text box, pressing spacebar will just add a space to your search.

Link to comment
Share on other sites

It wont work. Why? Because in the Spotlight menu the focus is never taken out of the text box. Click on any item in the menu and it executes instead of gaining focus. Because focus is always on the text box, pressing spacebar will just add a space to your search.

No, but enabling the default Quick Look keyboard shortcut cmd + Y shouldn't be a problem when hovering over a result.

Link to comment
Share on other sites

Spotlight always functioned as an app launcher as well, no?

Am I forgetting something?

Not quite. In Tiger, it didn't default to an application launcher, that is, if you hit Return, you opened up the unique Spotlight search window. But in Vista (and now Leopard), hitting Return will default to the Top Hit, which makes much more sense, intuitively speaking.

Link to comment
Share on other sites

What he means is that it now defaults to an app rather than the Spotlight window.

So you type a name & hit return (like other app launchers) instead of typing a name, arrowing down to the app then hitting return.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.