Sub topic 6
Building a Finder search with criteria
This chapter assumes you can open Finder windows, switch views, and use menus and keyboard shortcuts. It also assumes you know that Spotlight keeps an index of file metadata, which the earlier chapter on Spotlight covered. Here you build a search from several conditions. A smart folder is just such a search, saved.
From a text search to a criteria search
Press Command-F in a Finder window to start a search. Typing a word searches file names and also file contents and metadata, so a plain text search often returns more than you want.
Criteria narrow the results. Each criterion is one row with three parts:
- An attribute, such as Kind, Name, or Last modified date.
- An operator, such as "is", "contains", or "within last".
- A value, such as "PDF" or "7 days".
To add the first row, click the + button at the right of the search bar. Click + again for each further row.
Choosing the scope
The scope is where Finder looks. Under the search bar you can choose This Mac, the current folder (shown by its name), or Shared if you are browsing a network location. A narrow scope gives faster, less noisy results. If you search from your Documents folder, pick the Documents scope so downloads and system files stay out of the list.
How rows combine
By default, every row must match. A result needs to satisfy row one and row two and row three. This is an "all" match.
If you hold the Option key, the + button changes to an ellipsis (…). Clicking it adds a group of rules that you can set to match any, all, or none of the conditions. Use "any" when several alternatives are acceptable, such as Kind is PDF or Kind is Pages Document.
Useful attributes
The first pop-up menu lists common attributes. Choose Other… to see the full list of metadata fields. Tick In Menu beside an attribute to keep it in the short list.
| Attribute | Typical operator | Example value |
|---|---|---|
| Kind | is | |
| Last modified date | within last | 7 days |
| Name | contains | invoice |
| Tags | is | Red |
Tags appear in this list too. A tag criterion queries the same metadata that a sidebar tag click uses.
The same search in Terminal
Each row is a test on a metadata attribute. The mdfind command runs such tests from Terminal. This query matches the row "Last modified date within last 7 days", scoped to Documents:
mdfind -onlyin ~/Documents 'kMDItemFSContentChangeDate >= $time.today(-7)'Seeing the query text makes it easier to reason about what a row does. It also helps when a search returns something you did not expect.
Common mistakes
- Wrong scope. A search set to This Mac returns far more than one set to a folder. Check the scope before you judge the results.
- Name versus contents. "Name contains" searches file names only. The plain text search also looks inside documents.
- Expecting "any" by default. Rows combine as "all" unless you build an "any" group with Option and ….
- Unindexed locations. Spotlight only finds items it has indexed. Folders excluded in Spotlight privacy settings return nothing.
Exercise
You want PDF files in your Documents folder that you changed in the last 7 days. Which scope and criteria rows do you set, and how do the rows combine?
Show answer
Set the scope to the Documents folder. Add one row with Kind is PDF and a second row with Last modified date within last 7 days. Rows combine as "all" by default, so a file must satisfy both.