Sub topic 11
Saved searches that stay up to date
A saved search, which Finder calls a Smart Folder, is a search you store and reopen later. It looks like a folder, but it holds no files. Each time you open it, macOS runs the search again against the Spotlight index. A "PDFs changed this week" folder therefore stays accurate without any maintenance.
This chapter assumes you can run a basic search in Finder, know that Spotlight searches an index, and can read a short Terminal command. The Terminal parts are optional.
What a Smart Folder is
A Smart Folder is a stored query. It has three parts:
- Criteria: conditions such as "Kind is PDF" and "Last modified within the last 7 days".
- Scope: where to search, either This Mac or a specific folder.
- Sort and view settings: how the results are displayed.
Because the results come from a live query, three things follow:
- New files that match appear without any action from you.
- Files that stop matching disappear. Rename a file so it no longer fits the name criterion, and it leaves the folder.
- The files stay where they are. A Smart Folder shows the real files, not copies or aliases.
The diagram shows why a Smart Folder is only as good as the index. If Spotlight does not know about a file, the Smart Folder cannot show it. The troubleshooting chapter covers that case.
Creating a Smart Folder
- Switch to Finder and choose File > New Smart Folder. A window opens with a search bar and a scope selector.
- Choose the scope: This Mac or the name of the folder you were viewing. A narrower scope gives faster, less noisy results.
- Click the + button at the right side of the search bar. A row appears with two pop-up menus, an attribute on the left and a value on the right.
- Pick the attribute, such as Kind, then set its value, such as PDF.
- Click + again to add more rows. Finder requires every row to match unless you change that (see the next section).
- Click Save. Enter a name, choose where to store it, and select Add To Sidebar if you want one-click access.
You can also start from a normal Finder search. Press Command-F in a Finder window, type a term, add criteria with +, and click Save. This is often the quickest route, because you can see the results while you refine the query.
Useful criteria
The first menu lists common attributes. Choose Other... to open the full list of metadata attributes, and tick In Menu to keep ones you use often within reach.
| Goal | Attribute | Value |
|---|---|---|
| Recent documents | Last opened date, or Last modified date | within last 7 days |
| One file type | Kind | PDF, Image, Document and so on |
| Files whose name contains a word | Name | contains "invoice" |
| Files whose text contains a word | Contents | contains "warranty" |
| Large files | File size | is greater than 500 MB |
| Items from one app's era | Created date | is before 2024-01-01 |
Relative dates such as "within last 7 days" are evaluated each time the folder is opened, which is what keeps the folder current. A fixed date such as "Created is 2026-11-01" never changes, so such a folder only stays current if files can still be added with that date.
Matching any, all, or none
By default all rows must match, which is an AND. To change this, hold Option while you click +. The button turns into ... and adds a compound row with a menu of any, all, or none. Rows indented under it follow that rule.
For example, a folder for "receipts and invoices that are PDFs" uses:
all of the following are true
Kind is PDF
any of the following are true
Name contains receipt
Name contains invoiceThe nesting gives you the same logic as kind:pdf (receipt OR invoice) in a Spotlight search, with the ability to save it.
Editing and managing a saved search
Open the Smart Folder, then click the gear (Action) button in the toolbar and choose Show Search Criteria. The criteria rows appear, and you can change them. Click Save again to keep the changes. If the search bar is hidden, Command-F inside the Smart Folder also brings it back.
Other things you can do:
- Drag it to the sidebar to add it, or drag it out of the sidebar to remove the shortcut. Removing the shortcut does not delete the saved search.
- Rename or duplicate it like any other file. Duplicating is a fast way to make a variant, for example the same query with a different scope.
- Change the view to list, icon, column, or gallery, and sort by any column. The view settings are saved with the search.
By default Finder stores saved searches in ~/Library/Saved Searches. Each one is a file with the extension .savedSearch.
How the saved file works
A .savedSearch file is a property list. It contains the scope and the query that Spotlight runs. You can inspect it from Terminal:
ls ~/Library/Saved\ Searches
plutil -p ~/Library/Saved\ Searches/"Recent PDFs.savedSearch"The second command prints the stored keys. Among them is a raw query written in the same attribute language that mdfind uses, for example one that tests kMDItemContentType and a date attribute. Keys can differ between macOS versions, so treat the file as something to read, not something to edit by hand. If you want to change a search, use the Finder criteria rows.
Because the stored query uses the same attributes as mdfind, you can reproduce a Smart Folder from Terminal. This command lists PDFs in Documents changed in the last seven days:
mdfind -onlyin ~/Documents 'kMDItemContentType == "com.adobe.pdf" && kMDItemFSContentChangeDate >= $time.today(-7)'The single quotes stop the shell from treating $time as a variable. Use mdls on a file to find the attribute names you can query.
According to its manual page, mdfind can also run a saved search by name:
mdfind -s "Recent PDFs"That is useful in scripts, because you edit the criteria in Finder and the script follows the change.
Limits and gotchas
A Smart Folder inherits the behavior of the index and of Finder. These are the points that surprise people most.
- Deleting from a Smart Folder deletes the real file. The items shown are the originals. Moving one to the Trash moves the original to the Trash. To remove only the Smart Folder, delete the
.savedSearchfile or the sidebar shortcut. - You cannot store files in it. Dragging a file into a Smart Folder does not file it anywhere. Finder may refuse the drop or do nothing useful, because membership is decided by the criteria.
- Excluded locations never appear. If you excluded a folder in Spotlight settings, it is not indexed, and no saved search will find files in it. This includes locations you added under Search Privacy.
- Unindexed volumes are empty. Some external drives and network shares are not indexed. A scope of This Mac will not include their files unless Spotlight indexes them.
- Content searches depend on text extraction. "Contents contains" works for files whose text Spotlight can read. A scanned image of a page has no text unless it has been through text recognition.
- A stale index gives stale results. If the folder misses files you know match, check the index before you edit the criteria.
- Large scopes can be slow to load. A search over the whole Mac with a broad Contents condition can take a moment. Narrow the scope or add a Kind condition.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Folder is empty | Scope is a folder that has no matches, or the criteria use AND where you meant OR | Check the scope. Use Option-click on **+** to build an "any" group. |
| A recent file is missing | The file is in an excluded folder, or the index is stale | Check Spotlight Search Privacy settings, then check indexing with `mdutil -s /`. |
| Results never change | A fixed date was used instead of a relative date | Change the date condition to "within last N days". |
| Duplicate-looking names | The same file name exists in several folders | Add the Path column or use **View > Show Path Bar** to tell them apart. |
| Smart Folder is not in the sidebar | **Add To Sidebar** was not ticked when saving | Drag the saved search from `~/Library/Saved Searches` into the sidebar. |
Exercises
Exercise
You save a Smart Folder with the criteria "Kind is PDF" and "Last modified date is within last 7 days". Two weeks later you open it. Explain which PDFs it shows and why you did not have to update it.
Show answer
It shows the PDFs modified in the seven days before you opened it. The folder stores a query, not a list of files. Spotlight runs the query against the index each time the folder is opened, and the relative date is recalculated each time. Older PDFs drop out and new matching ones appear.
Exercise
Describe how to build a Smart Folder that shows files whose name contains "receipt" or "invoice", but only PDFs. Which key do you hold, and what does the criteria structure look like?
Show answer
Create a new Smart Folder, add a Kind is PDF row, then hold Option and click + to add a compound row set to "any". Under it, add Name contains receipt and Name contains invoice. The top level is "all", so the PDF condition and the any-group must both match.
Exercise
A teammate selects every item in a Smart Folder and presses Command-Delete to "clear it out". What happens, and what should they do instead?
Show answer
The original files are moved to the Trash, because a Smart Folder lists the real files. To remove only the Smart Folder, they should delete the .savedSearch file or remove its sidebar shortcut.
Exercise
Write an mdfind command that lists images in ~/Pictures modified in the last 30 days. Hint: use kMDItemContentTypeTree with the type public.image.
Show answer
mdfind -onlyin ~/Pictures 'kMDItemContentTypeTree == "public.image" && kMDItemFSContentChangeDate >= $time.today(-30)'