Sub topic 7
Creating and saving a smart folder
This chapter assumes you can navigate Finder, apply tags, and run a basic Finder search. You should also know that Spotlight indexes file metadata, which the earlier chapters on tags and search criteria covered. Here you will turn a search into a saved smart folder, and you will learn what a smart folder does and does not do.
What a smart folder is
A smart folder is a saved search. It holds no files. When you open it, Finder runs the stored query against the Spotlight index and shows the matching items. The files stay where they are, and the smart folder lists them in one place.
Three consequences follow from this:
- The contents update on their own. A file that starts to match appears, and a file that stops matching disappears.
- Deleting an item from a smart folder deletes the real file, because you are looking at the original. Deleting the smart folder itself removes only the saved query.
- Results are only as good as the Spotlight index. If a file is not indexed, no smart folder will list it.
Creating a smart folder, step by step
There are two routes. Both end at the same dialog.
Route 1: from the menu
- In Finder, choose File > New Smart Folder. A new window opens with a search field and a Search: scope bar.
- Click the + button at the right of the bar under the title. A row of criteria appears.
- Set the scope: This Mac, a specific folder, or Shared. The scope sets where Finder looks.
- Build the criteria with the pop-up menus (see below).
- Click Save, name the smart folder, and choose where to store it.
- Tick Add To Sidebar if you want a sidebar shortcut.
Route 2: from a search you already ran
- Open a folder and type in the Finder search field. Choose a suggestion, or press Return.
- Click Save in the upper right of the window.
- Name it and click Save.
Route 2 keeps the search text and the scope. Starting from the folder you are in is a good habit, because the scope then begins at that folder instead of the whole Mac.
Building criteria
Each criteria row has an attribute menu on the left, an operator in the middle, and a value on the right. The default attribute is Kind. Open its menu and choose Other… to browse every attribute Spotlight knows about. In the Other list you can tick In Menu to keep an attribute handy.
Common attributes:
| Attribute | Typical operator | Example value |
|---|---|---|
| Kind | is | |
| Last modified date | is within last | 7 days |
| Created date | is before | a fixed date |
| Name | contains | invoice |
| Tags | is / contains | Red |
| File size | is greater than | 10 MB |
Match all or any
Hold the Option key and the + button changes to …. That adds a nested group where you choose any, all, or none for the rows inside it. Without nested groups, all rows must match, which is an AND.
For example, "PDFs that carry the tag Red" needs two rows joined by AND: Kind is PDF, and Tags is Red. "Anything tagged Red or Orange" needs a group set to any.
Dates are relative
Use is within last with a number of days, rather than a fixed date, when you want the folder to stay current. A fixed date gives a result that never changes. A relative window slides forward every day.
Hidden files and system files
A criterion such as File invisibility or System files is not in the default list. If you need to include them, add them through Other. Leaving them out keeps results short.
Example: a "This Week" folder
Goal: every document you changed in the last seven days, found in your Documents folder.
- Choose File > New Smart Folder.
- Click Documents in the scope bar.
- Click +. Set the first row to Last modified date, is within last, 7, days.
- Click + again. Set Kind to Document.
- Click Save, name it
This Week, and tick Add To Sidebar.
The same search can be written as a Spotlight query in Terminal. This one covers only the date criterion.
mdfind -onlyin ~/Documents 'kMDItemFSContentChangeDate >= $time.today(-7)'If Finder and Terminal give different results, the cause is usually the scope or a missing second criterion, not the query engine.
Example: a tag-driven folder
Tags are metadata, so a smart folder can use them as a criterion. Suppose you tag urgent work Red.
- Choose File > New Smart Folder and set the scope to This Mac.
- Set the first row to Tags, is, and type
Red. - Save it as
Urgentand add it to the sidebar.
The Terminal equivalent is:
mdfind -onlyin ~/Documents 'kMDItemUserTags == "Red"'This is the difference between a tag and a smart folder. Applying the tag is something you do by hand to one file. The smart folder gathers every tagged file automatically.
Where it is saved
When the Save dialog appears, the default location is ~/Library/Saved Searches. You can pick another folder, such as the Desktop, but the sidebar entry only needs the file to exist somewhere. If you move or delete the file afterward, the sidebar item stops working. The file format is covered in a later chapter. For now, you can check the default location:
ls ~/Library/Saved\ SearchesEach smart folder is a file with the extension .savedSearch.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Folder is empty | Scope is too narrow, or a criterion is wrong | Open it and check the scope bar and each row |
| A file you expect is missing | The file is not indexed, or sits in a folder excluded from Spotlight | Check Spotlight privacy settings and re-index if needed |
| Results include files you did not want | Rows are combined with AND but a looser operator was chosen | Tighten the operator, or add a Kind row |
| Old results never change | A fixed date was used | Switch to a relative date |
| The sidebar item shows no results after a rename | The saved file was moved | Re-save the folder and add it again |
| Tag criterion finds nothing | The tag name changed or has different capitalisation | Retype the tag name from the current tag list |
Behaviours worth knowing
- Sorting and views are stored with the smart folder window. You can choose a list view and group by Kind, and Finder remembers it.
- Dragging files in does not work as you might expect. A smart folder cannot receive files, because it contains nothing.
- Network volumes are only searchable when their content is indexed. Many servers do not provide an index, so results there can be missing.
- Large scopes such as This Mac take longer than a single folder. A narrow scope is faster and gives less noise.
Summary
A smart folder is a saved Spotlight query with a scope, criteria, and a view. You create it with File > New Smart Folder or by saving a Finder search, then choose a name, a location, and whether it appears in the sidebar. Use relative dates, set the narrowest scope that works, and expect the results to be only as complete as the index.
Exercise
You created a smart folder named Urgent with the criterion Tags is Red, and added it to the sidebar. Later you drag a file out of it to your Desktop. What happens to the original file, and what happens if you instead delete the Urgent smart folder from the sidebar?
Show answer
Dragging the file out moves the original file to the Desktop, because the smart folder only displays real files. Once the file is moved, it still carries the Red tag, so it still appears in Urgent, provided the scope covers the Desktop. Deleting the smart folder removes only the saved search file and the sidebar item. Your files and their tags are not affected.
Exercise
Write the criteria rows for a smart folder that lists PDFs larger than 10 MB, modified in the last 30 days, in your Downloads folder. Say which scope you choose and why you use a relative date.
Show answer
Scope: Downloads. Rows: Kind is PDF; File size is greater than 10 MB; Last modified date is within last 30 days. All rows must match, which is the default AND behaviour. A relative date makes the window slide forward each day. A fixed date would stay the same and the folder would go out of date.