macOS: How to use Spotlight’s query language to create an All My Files-like feature

Apple removed the prefab option, but with a raw query, you can simulate it.

mac finder icon
Apple

Recently, I noted that the All My Files feature present in macOS for several releases until macOS 10.13 High Sierra, had disappeared, replaced by an inferior Recents display—and that it couldn’t be restored. A Macworld reader wrote in to note that with the use of Spotlight’s lightly documented underlying query language, you could restore the function.

I avoided this in this previous column for two reasons, but if you’re willing to go through some configuration and picky details, you could find it worthwhile. First, it requires learning some programming-like syntax to construct a query, and even the tiniest error in typing or construction will keep it from working without any errors that give you clues of how to fix it. That can be frustrating, but I can at least provide the recipe to paste in. Second, depending on the age of your Mac and how many files on yoru drive, the All My Files replacement could take a long time to run or update, or even slow the Finder down.

With those provisos, here’s how you do it. Spotlight has an underlying “raw query” language for which Apple last updated the documentation in 2011. This language lets you specify a search parameter that’s not available through a preset popup menu selection in Smart Folders in the Finder.

  1. In the Finder, open a new folder and click the Recents item in the Sidebar.
  2. From the gear menu, select Show Search Criteria.
  3. In the field next to Raw Query, enter exactly the following: (kMDItemFSName="*.*")
  4. Click the Date Modified column to sort them from newest to oldest.
  5. Click Save.
  6. Name the search query All My Files, and check the box to put it in the Sidebar.

Note that above the query, the Spotlight constraint will show “Search: This Mac [Recents] Shared,” where Recents is selected. That limits the scope to document types in common locations instead of files found everywhere on your Mac. If you click This Mac, you’ll see the same query performed against the entire set of locally indexed files, which will include database files and other documents used for system and app purposes that you never need to know have changed and with which you don’t interact.

(You can also use these steps to get to a similar place, although it won’t be bound within the Search: Recents parameter.

  1. Choose File > New Smart Folder.
  2. Click the + next to Save.
  3. Select the pop-up menu with Name in it.
  4. Choose Other.
  5. Type Raw Query into the search field.
  6. Select the Raw Query match and click OK.
  7. Proceed from step 3 above.

The Smart Folder should populate fairly quickly with results. If it takes a long time or slows the Finder (or your Mac) down, you can limit the query, which should speed it up. If you wanted to get all files modified in the last week, you could change the query above to:

(kMDItemFSName="*.*") && (kMDItemFSContentChangeDate >= $time.this_week(-1))

mac911 raw query finder IDG

The Raw Query field doesn’t show long queries, so you might want to type it in and edit it elsewhere to be sure it’s correct.

On Apple’s main documentation page, it describes how to define date ranges. You can string required conditions to the query with && with a space on either side. (Yes, two ampersands for “and” to connect conditions, not a single one, which does a binary comparison.)

You may still see too many results from files that are indexed and show up in these results, but about which you don’t care to see. For me, that’s individual email messages, which I can find in my email program.

If you want to get more baroque, you can look up more parameter types at the Spotlight Metadata Attributes page, although you’ll have to puzzle out valid values and other details. I have a more elaborate query for my All My Files that looks like this:

(kMDItemFSName="*.*") && (kMDItemFSContentChangeDate >= $time.this_week(-1)) && (kMDItemKind !="Mailsmith message file") && (kMDItemFSName !="*.freelist") && (kMDItemFSName !="*.plist") && (kMDItemFSName !="*.messageData")

This reads in English as, “Find all files modified within the last week where the file kind isn’t ‘Mailsmith message file’ and the file’s name doesn’t end with ‘.freelist’ or ‘.plist’ or ‘.messageData.’” This gives me a more readable list of files about which I want to see recent activity.

Ask Mac 911

We’ve compiled a list of the questions we get asked most frequently along with answers and links to columns: read our super FAQ to see if your question is covered. If not, we’re always looking for new problems to solve! Email yours to mac911@macworld.com including screen captures as appropriate, and whether you want your full name used. Every question won’t be answered, we don’t reply to email, and we cannot provide direct troubleshooting advice.

  
Shop Tech Products at Amazon