Sub topic 11
Saving searches as smart folders
A smart folder is a saved Finder search that behaves like a folder. You define the rules once, and the Finder re-runs them every time you open it. This chapter assumes you can run a basic Finder search (Command-F), apply tags to files, and sort a window by column.
What a smart folder is
A smart folder holds no files. It stores a query: a scope (where to look) and a set of criteria (what to match). When you open it, the Finder asks Spotlight for everything that matches right now. A file that gains the tag "Urgent" tomorrow appears in the folder without any action from you.
The file behind a smart folder has the extension .savedSearch. It lives in ~/Library/Saved Searches unless you choose another location when saving. It is a small property-list file describing the query.
How a smart folder gets its results
Because the results come from the Spotlight index, a smart folder can only find what Spotlight has indexed. Items in folders listed under System Settings > Spotlight > Search Privacy never appear.
Creating a smart folder
There are two routes.
- Choose File > New Smart Folder. A search window opens with no criteria.
- Or press Command-F in any Finder window, run a search, and click Save.
Then build the rules:
- Set the scope. Choose "This Mac" to search everywhere, or the name of the current folder to limit the search to it.
- Click the plus (+) button on the right to add a criterion row.
- Pick an attribute from the first menu, such as Kind, Last opened date, Last modified date, Created date, Name, or Contents.
- Pick or type the value in the second menu, such as "PDF" or "within last 7 days".
- Add more rows. By default every row must match (logical AND).
- Click Save, give it a name, and choose a location.
- Leave "Add To Sidebar" ticked if you want one-click access.
Using tags as criteria
Tags are not in the default attribute list. In the first menu, choose Other…, search for "Tags", and tick "In Menu" so it stays available. Then set the row to Tags contains Urgent.
This is where smart folders pay off. A tag can be attached to files in any location, and the smart folder gathers them in one view. That is why tags and smart folders appear together in a folder-design plan.
Matching "any" instead of "all"
Hold Option while clicking the plus button. It turns into an ellipsis (…) and adds a nested group, which has its own "any", "all" or "none" setting. Use it to build rules such as "Kind is PDF or Kind is Pages document, and modified within the last 7 days".
Useful recipes
| Smart folder | Scope | Criteria |
|---|---|---|
| This week's work | Documents | Last modified date within last 7 days |
| Big files | This Mac | File size is greater than 500 MB |
| To review | This Mac | Tags contains Urgent |
| Old downloads | Downloads | Last opened date is before a chosen date |
| Screenshots | This Mac | Kind is Image, Name begins with "Screenshot" |
For "Big files", the file-size attribute is not in the default menu. Add it through Other… in the same way as Tags.
Editing and managing a smart folder
- To change the rules, open the smart folder and choose Show Search Criteria from the action (gear) menu, or click the plus button area to reveal the rows. Edit them, then click Save again.
- To rename it, select it in the Finder and press Return, as you would for any file.
- To remove it from the sidebar, drag it out of the sidebar until the pointer shows a puff of smoke, or Control-click it and choose Remove from Sidebar. This does not delete the saved search.
- To delete it entirely, move the
.savedSearchfile to the Trash. The files it displayed are untouched.
Checking the same query in Terminal
Spotlight is the engine behind both the Finder search and the mdfind command. Running a query in Terminal helps you confirm what a smart folder should return. The command from the plan lists files in Documents that carry the tag "Urgent":
mdfind -onlyin ~/Documents "kMDItemUserTags == 'Urgent'"You can combine conditions with &&. This one finds PDFs in Documents changed in the last seven days:
mdfind -onlyin ~/Documents "kMDItemContentType == 'com.adobe.pdf' && kMDItemFSContentChangeDate >= \$time.today(-7)"The backslash before $time stops zsh from treating it as a shell variable. Each output line is a file path, and an empty result means no match. If the Terminal result and the smart folder disagree, check that the folder isn't excluded in Search Privacy.
Common problems
- The folder is empty but files should match. Check the scope first. A scope set to a single folder hides matches elsewhere. Then check that the indexed location isn't excluded in Search Privacy.
- Recent files are missing. Spotlight may still be indexing, which happens after a macOS update or a newly connected drive. Wait a few minutes.
- Files on an external drive don't appear. The drive must be indexed. Drives formatted for Windows and some network volumes are indexed poorly or not at all.
- Too many results. Add a Kind or date criterion, or narrow the scope. Broad "Name contains" rules over "This Mac" match system files too.
- Cloud files. Items in iCloud Drive that are not downloaded still appear, because their names and metadata are local. Contents searches may miss files that are not stored on the Mac.
- You can't save new files into it. Dragging a file into a smart folder does nothing useful, since membership is decided by the rules and not by location. Save the file somewhere real and let it match.
Smart folders in a folder-design plan
Use real folders for where things live, and smart folders for views across them. A project folder holds a project's files for good. A smart folder such as "Modified this week" cuts across every project. Keep the number small: five or six that you open weekly are more useful than twenty you forget.
Exercise
You tag invoices "Unpaid" in several project folders. Describe how to build one smart folder that lists all unpaid invoices that are PDFs, and say what happens to a file in the smart folder when you remove its "Unpaid" tag.
Show answer
Choose File > New Smart Folder and set the scope to This Mac (or Documents). Add a row for Tags contains Unpaid, using Other… to add Tags to the menu if needed. Add a second row for Kind is PDF. Because both rows must match by default, only tagged PDFs appear. Click Save, name it, and tick Add To Sidebar. When you remove the "Unpaid" tag from a file, it no longer matches, so it drops out of the smart folder the next time the results refresh. The file itself stays where it was.