Sub topic 11
Saved searches that stay up to date
This chapter assumes you can search in Finder (covered earlier) and know that Spotlight searches from an index of your files. A saved search, called a Smart Folder, stores a search query instead of files. Each time you open it, Finder runs the query against the index and shows the current matches.
What a Smart Folder is
A Smart Folder looks like a normal folder in Finder, but it holds no files. It holds a set of criteria, such as "PDFs modified in the last 7 days." The files it lists stay in their real locations. When a new file matches the criteria, it appears in the Smart Folder. When a file stops matching, it disappears from the list.
Create a Smart Folder
- In Finder, choose File > New Smart Folder.
- Choose where to search: This Mac, or the folder you were viewing.
- Click the + button under the search field to add a criterion. The first menu picks the attribute, such as Kind, Last opened date, Created date, or Name. The next controls set the value.
- Add more criteria as needed. All of them must match by default. Hold the Option key and the + button changes to an ellipsis (...). Click it to build "any" or "none" groups.
- Click Save, type a name, and choose a location.
- Leave "Add To Sidebar" selected if you want one-click access.
For example, to track recent screenshots, use Kind is Image, Created within the last 7 days, and Name contains "Screenshot".
Change or remove a Smart Folder
Open the Smart Folder and click the gear (Action) button in the toolbar. Choose Show Search Criteria to edit the rules. Changes to the criteria are saved when you click Save again in the search bar.
To delete it, select the Smart Folder in Finder or the sidebar and move it to the Trash. This deletes only the saved search. Your files are not affected.
Where the search is stored
By default, Smart Folders are saved in ~/Library/Saved Searches as files ending in .savedSearch. Each one is a small property list holding the query. You can list them in Terminal:
ls ~/Library/"Saved Searches"If you save one elsewhere, such as the Desktop, you can move or copy it like any file.
Common errors
- Deleting files from inside a Smart Folder. The items shown are the real files. Moving one to the Trash from the Smart Folder trashes the original.
- Expecting matches from excluded folders. A Smart Folder uses the Spotlight index. Folders you excluded in Spotlight settings never match. If results are missing, check the exclusion list and index status, covered in the troubleshooting chapter.
- Results that seem stale. If the index is out of date, the list is too. A rebuilt index fixes this.
- A search that is too broad. "This Mac" includes system and app files. Restrict the scope to a specific folder, or add a Kind criterion.
Terminal equivalent
A Smart Folder is essentially a stored mdfind query. This command lists PDFs in Documents, the kind of query a Smart Folder with Kind is PDF would run:
mdfind -onlyin ~/Documents "kMDItemContentType == 'com.adobe.pdf'"Terminal results are not saved, so use a Smart Folder when you want a result you can reopen later.
Exercise
You created a Smart Folder called "Recent PDFs" and later no longer need it. You select it and move it to the Trash. Are the PDFs it listed deleted? Why or why not? What would happen if you had opened it and trashed one listed PDF instead?
Show answer
No. The Smart Folder stores only the search criteria, so trashing it removes only the saved search. Trashing a PDF from inside the Smart Folder would move the real file to the Trash, because the listed items are the original files.