Sub topic 13
Where smart folders live on disk
This chapter assumes you can create a smart folder in Finder, know what Spotlight metadata is, and can open Terminal and run basic commands. Here you will see that a smart folder is a small file, and you will learn how to find it and read it.
A smart folder is a saved query
A smart folder does not hold your files. It holds a search. When you open it, Finder reads the stored search and asks Spotlight to run it again. This is why the results change as your files change.
Finder stores that search in a file with the extension .savedSearch. When you choose Save in a Finder search window, the default location is the Saved Searches folder inside your Library folder. The Library folder is hidden by default in Finder, but Terminal can reach it.
ls ~/Library/Saved\ SearchesThe backslash before the space tells the shell that "Saved Searches" is one name. Each .savedSearch file in the output is one smart folder you saved there. If you chose another location when saving, the file is in that folder instead.
What is inside the file
A .savedSearch file is a property list, often called a plist. A plist is a structured file of keys and values that macOS uses for settings. Finder usually writes it in a binary form that a text editor cannot read. The plutil tool prints it in a readable form.
plutil -p ~/Library/Saved\ Searches/Recent\ Documents.savedSearchThis example reads a smart folder named Recent Documents. Replace the name with one of your own. The output lists keys such as these:
| Key | What it holds |
|---|---|
| `RawQuery` | The Spotlight query string that Finder runs |
| `SearchCriteria` | The search scope and the settings Finder shows in the criteria editor |
| `RawQueryDict` | The same search in structured form, including the folders to search |
The exact keys can differ between macOS versions, so treat this table as a guide. Read your own output and look for the query.
The RawQuery value uses the same language as the mdfind command. That link lets you test a smart folder from Terminal.
mdfind -onlyin ~/Documents 'kMDItemFSContentChangeDate >= $time.today(-7)'If this command lists the files you expect, the criteria are sound. If a smart folder is missing items, the problem is probably in the scope or the index, not in the file itself.
How the pieces connect
Handling these files with care
Because a smart folder is a file, you can treat it like one. You can copy it to a backup folder, move it to another Mac, or delete it. Deleting a .savedSearch file removes only the saved search. Your documents are not affected.
Exercise
Exercise
You saved a smart folder named Invoices, but ls ~/Library/Saved\ Searches does not list it. Give two likely explanations, and name the command that shows the stored query once you find the file.
Show answer
You may have saved it to a different location, such as the Desktop, because the Library folder is only the default. Or the name may differ from what you typed, so check for a similar .savedSearch name. Once you find the file, run plutil -p on its path to print the stored query, and look at the RawQuery key.