Sub topic 7
Creating and saving a smart folder
A smart folder is a saved search that Finder shows like a folder. It holds no files. Each time you open it, Finder runs the stored query against the Spotlight index and lists the matches. This chapter assumes you know how to apply tags, how Spotlight metadata works, and how to build a Finder search with criteria, all covered earlier.
What a smart folder stores
Moving or renaming a file does not break a smart folder, because the search matches on metadata rather than on location. The folder saves two things: the query and the criteria that narrow it. By default, Finder writes this as a .savedSearch file in ~/Library/Saved Searches.
Creating one step by step
Use a worked example: a smart folder of every document you changed in the last seven days.
- In Finder, choose File > New Smart Folder. A search window opens.
- Click the plus button (+) at the right of the search bar to add a criterion.
- Set the first criterion's attribute to Last Modified Date, then choose "within last" and enter 7 days.
- Click the plus button again. Set the attribute to Kind and the value to Document.
- Use the "Search" scope buttons, such as This Mac or a specific folder, to limit where Finder looks.
- Click Save. Enter a name such as Recent Documents.
- Keep "Add To Sidebar" checked if you want a sidebar shortcut.
Finder saves the file in ~/Library/Saved Searches by default. You can pick another location, but the sidebar shortcut is usually all you need.
Combining criteria
Each added criterion narrows the results, because Finder treats them as "all of these". To match any of several conditions, hold Option and click the plus button. The row then offers "any", "all" and "none" compound options.
The Terminal gives a rough equivalent of the same query:
mdfind -onlyin ~/Documents 'kMDItemFSContentChangeDate >= $time.today(-7)'This returns files under Documents modified in the last seven days. It is the kind of criterion a smart folder saves.
Using a tag as a criterion
Tags make a strong criterion because you control them. To build a smart folder for everything tagged Red:
- Start a new smart folder.
- Choose Other from the attribute menu if Tags is not listed. Search for "Tags" and tick "In Menu".
- Set the attribute to Tags, with the value "Red".
- Save it.
Common errors
- The folder is empty. The index may be incomplete for that location, or a criterion is too strict. Remove criteria one at a time to find the one that excludes everything.
- Too many results. The scope is probably This Mac. Restrict it to a folder.
- You expect to delete files by deleting the smart folder. Deleting a smart folder removes only the saved search. The matching files stay where they are. Deleting an item from inside it, however, moves the real file to the Trash.
Checking the result
You can confirm the file exists from Terminal:
ls ~/Library/Saved\ SearchesIf your folder does not appear, you may have saved it elsewhere, or you may not have saved it at all. A search window that has not been saved disappears when you close it.
Exercise
You save a smart folder with the criteria Kind is Document and Last Modified Date within the last 7 days. Later you move one matching document to another folder on the same disk. Does it still appear in the smart folder, and why?
Show answer
Yes. The smart folder stores a query, not a list of files. The moved file still matches the criteria and Spotlight has updated its location, so it appears in the results as long as it is inside the search scope.
Exercise
How would you make a smart folder match files that are either tagged Red or tagged Green, rather than both tags?
Show answer
Hold Option and click the plus button to get compound criteria, then choose "any". Add one Tags criterion for Red and one for Green inside it.