On the surface, searching with Spotlight is pretty straightforward. In my previous article, I explained how to perform basic searches, and how to access other Spotlight features. 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, such as using keywords to limit your search to specific dates, authors, or file types, you can narrow down your search to specific types of data, exclude terms, and more, helping Spotlight to locate exactly what you need.
Using the right words
If you search for just one word in Spotlight, the results are pretty simple. But if you search for more than one word, things get a bit more complex. Type
time machine in the Spotlight search menu, and you’ll get a list of every file containing both words.
Every Spotlight query is an
AND search by default. This means the program looks for files containing all the words you type. This search will turn up any files that mention Yosemite’s Time Machine backup feature, but also an IMDB search result for a movie of that name, a Wikipedia article on time travel, an article I wrote a few years ago about using the command line to control Time Machine, but it may also find an email from a friend discussing the best time to swing by and fix a 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 phrase that you’ve typed 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.
Use Boolean searching
Spotlight also supports true Boolean searching, which uses logical operators (
NOT) to pinpoint results.
For example, if you type
“time machine” OR morlock, you’ll get references to Yosemite’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 Info window, click on the triangle next to 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
HouseProject 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. It’s a good idea to use
“HouseProject” rather than
“House Project” because that way Spotlight only searches for the single, uncommon word, instead of finding every file with the words “house” and “project.”
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. Create a new document and select Service for the type.
- Select Files & Folders from the Library column.
- 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.
- Press Command-S to save the file, and choose to save it as an application.
To put your new Automator workflow to use, simply drag any files on its icon. 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 insert a space before the colon). 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 example, 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, such as,
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, such as 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, including applications, if you have that category in your search results. You can also use the
date:keyword with yesterday and tomorrow (for the latter, Spotlight can’t tell which files you’re going to use or create, but restricts its results to iCal events and to-do items).
You can also specify more parameters, such as whether a file was created or modified on a certain date, an exact date, or a range of dates. For example, you can type
created:12/25/13 to find files authored on that date; this is a good way to find photos you took on a specific date. Type
modified:<11/30/14 to look for files changed before that date; or type
created:1/1/12-12/31/14 to locate files created between these two dates.
Search by Kind: One of the most useful ways to narrow down a search is by using
kind:keyword. This allows you to restrict your list of results to a certain type of file. 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 email messages, music files, System Preferences, applications, and more.
Spotlight 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, below. 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|