Create good queries in Spotlight
On the surface, searching with Spotlight is pretty straightforward. In our previous installment, we covered the basics of using and customizing the Spotlight menu. But if your search involves multiple terms, or if you need to narrow down your results to dig up a particularly elusive file, knowing how to put together a good search query will pay off. By mastering a few simple tricks, you can limit your search to specific types of data, exclude terms, and more—helping Spotlight locate exactly what you need. and then take you inside some of its lesser know features—including how to use keywords to limit your search to specific dates, authors, or file types.
Fix your phrasing
Every Spotlight query is an AND search by default. This means the program looks for files containing all the words you type. For instance, if you enter
time machine, Spotlight seeks out anything that contains both the word time and the word machine. So the search will turn up any files that mention Leopard’s new Time Machine feature, as well as e-mails from your IT administrator discussing the best time to swing by and fix your machine.
You can narrow down the search results by using quotation marks—this tells Spotlight that the words must appear next to one another. If you type
"time machine", Spotlight will look only for files that contain the exact term inside the quotation marks. It will find Time Machine.doc and any file containing the term time machine, but it will skip over your presentation on the evolution of machines through time. You don’t even have to use both quotation marks; typing only the first one tells Spotlight that the words following it must appear together. However, if you want to add more search terms after the phrase, you’ll need to add the closing quotation mark.
Apply Boolean searching
One of the biggest additions to Spotlight is support for true Boolean searching, which uses logical operators (AND, OR, and NOT) to pinpoint results.
For instance, if you type
"time machine" OR morlocks, you’ll get references to Leopard’s backup tool, as well as any files related to H. G. Wells’s fictional species. To find files that include time machine but make no mention of H. G. Wells, type
"time machine" NOT Wells. When you perform a Boolean search, make sure to type operators in capital letters.
In addition to scouring your files’ names and contents, Spotlight peruses metadata—file information generated by the program or device that created the file. For example, a digital photo’s metadata may include information about the camera used to take the photo and about how the photo was taken: the camera type, focal length, color space, exposure time, and so on. If you want to find all photos taken with a certain camera, just enter its name or model number in the search field.
To see what sort of metadata a file is storing, select it in the Finder, press command-I to open the Get Info window, and click on the triangle next to More Info. However, you’re not limited to the metadata you see here. You can add your own keywords to any file. In the Get Info window, click on the triangle next to Spotlight Comments. In the text field that appears, enter any keywords that might help you in future searches, such as the project the file is related to or the last name of a person you associate with it. For example, by adding the comment
HOUSE08 to any files having to do with the purchase and remodeling of your new home, you’ll be able to find all those files with one easy search.
If you use this trick often, you may want to create an Automator workflow that lets you apply the same comment to multiple files at once. To do this, launch Automator, select Files & Folders from the Library column, and drag Set Spotlight Comments For Finder Items from the Actions list to the workflow pane. Click on Options, and enable the Show This Action When Workflow Runs option. Then select File: Save As Plug-In. Give the plug-in a name, such as Spotlight Comments, and select Finder from the Plug-In For pull-down menu.
To put your new Automator workflow to use, simply control-click (or right-click) on the files. In the contextual menu, select More: Automator: Spotlight Comments (or whatever you named your plug-in item). A dialog box will appear, allowing you to add your comments to dozens of files at once.
Take advantage of keywords
Even when you know what you’re looking for, you may get an overwhelming number of search results. To help limit searches to certain file types or time periods, use one of the many useful keywords that Spotlight understands. Place the appropriate keyword and a colon in front of your search term (but don’t accidentally insert a space before or after the colon—a common mistake).
Here how to take advantage of Spotlight’s keywords:
Search for File Names If you know the name of the file you’re looking for, you can limit your search to file names by using the
name: keyword. For instance, when you type
name:machine, Spotlight will find only files that contain the word machine in their names (though your search results may also turn up bookmarks, iCal events, and other items). As with regular search queries, you’ll need to use quotation marks to identify phrases—for example,
Find an Author If you can’t remember the contents of a file but you know the name of the person who created it, you can try using the
author: keyword. To look for a document written by your boss, Herbert, enter
author:herbert in the search field. There’s just one catch: Spotlight will find only files produced by programs that save this attribute—Mail, iChat, Word, Excel, Pages, Numbers, and a few others.
Check the Date Looking for a file that was created during a specific time period? Spotlight has a handle on dates. Typing
date:today will bring up files you created, read, received, or opened today. You can also use the
date: keyword with yesterday and tomorrow (for the latter, Spotlight restricts its results to iCal events and to-do items).
The latest version of Spotlight also lets you specify more parameters (whether a file was created or modified on a certain date), as well as enter an exact date or a range of dates. For example, you can type
created:12/25/07 to find files authored on that date; type
modified:<11/30/06 to look for files changed before that date; or type
created:1/1/06-12/31/06 to locate files created between these two dates. Unfortunately,
date: keywords don’t seem to work correctly all the time.
Search by Kind One of the most useful ways to narrow down a search is by using the
kind: keyword. This allows you to restrict your list of results to a certain file format. For instance, if you type
time machine kind:pdf, Spotlight will pull up only PDF files containing the words time and machine. You can also limit your search to e-mail messages, music files, System Preferences, applications, and more.
While the original Spotlight recognized only a limited number of file types, the Leopard version can look for files created by specific applications, as well as certain file formats. Searching for
kind:tiff will find files in one of those formats, and searching for
kind:powerpoint will show only documents created in one of those programs. For a list of useful keywords, see “My Kind of Keyword.” But remember, for the keywords to work, you must have the appropriate categories enabled in Spotlight’s preferences.
My Kind of Keyword
|To Search for:||Use:|
|Applications||kind:application, kind:applications, kind:app|
|E-mail messages||kind:email, kind:emails, kind:mail message|
|Folders||kind:folder, kind:folders, kind:fol|
|iCal Events||kind:event, kind:events|
|iCal To-Do Items||kind:todo, kind:todos, kind:to do|
|PDF files||kind:pdf, kind:pdfs|
|Preference panes||kind:preference, kind:preferences|
Spotlight’s other tricks
Better search functionality is the main attraction of Leopard’s new and improved Spotlight. But it has other clever tricks that may come in handy.
Instant Dictionary Need the definition for tarradiddle? Look it up in Spotlight. Whenever you type a word into the Spotlight menu, a short definition appears in the list of results. Hover your cursor over this definition to view the full definition in a tooltip.
Program Launcher Applications now appear as top hits, so you can launch them much more quickly. To fire up Safari, type
saf in the menu and press return.
Math Genius Type an equation into the Spotlight menu, and let your Mac do your math. For example, type
2*2, and you’ll get 4. If you need the area of a circle with a radius of 10 feet, type
pi*10*10. Need the square root of 1,024? Enter
sqrt(1024). How about 64 squared? Just type
Unfortunately, Apple has yet to publish a list of such commands, so you’ll have to memorize the basics for now.
[Kirk McElhearn writes about Macs and much more. Visit his blog, Kirkville, for information about Macs, iPods, books, music, and more.]