0

This is driving me nuts.

In Finder, in the left navbar, in Favourites section, is Recents.

I've actually created a second partition and installed a fresh macOS onto it. So my machine has 2 macOS partitions. From the fresh macOS, Recents is showing a load of files that I haven't even viewed since creating this macOS. They must be stored on the old partition somehow.

Remove recent documents history? ^ Here I see some suggestions. But nothing I've tried works permanently.

I can remove Recents from {left nav-bar}/Favourites, but if I add it back all the files are back again.

I can sysPrefs -> Siri&Spotlight -> SpotlightPrivacy -> 'Prevent Spotlight from searching these locations' -> {add oldPartition}, but: a) if I undo that action, Recents repopulates with all the old cruft b) (and this is mind-bending), if I copy a folder {oldPartition -> newPartition}/Users/pi/Desktop/foo/, and foo/ contains files that were previously showing up in Recents, they STILL SHOW UP in Recents. This has to be a bug.

I'm just being stubborn at this point. But I really want a fresh macOS + fresh start. And this annoys me.

Also, I like to feel in control of my OS, and what it's doing. And I have absolutely no idea what's going on here.

I'm guessing Spotlight stores a file on oldPartition which contains recent items. Can I force it to 're-index' so that these recent items are purged?

Or is there another way?

1 Answer 1

2

The "Recents" folder is not an actual, "physical" folder similar to other folders on your computer. It is a virtual folder, and the contents of it is simply computed when it is viewed. This is why you cannot get rid of the its contents by removing the "Recents" folder from Finder and adding it back in.

The "Recents" folder does not by Spotlight storing a file on your drive containing the most recent items. Therefore there's no way of forcing a re-index of this particular file with a list of recent items.

Instead the "Recents" folder simply works by sorting your files according to their "Last Opened" time (as seen in Finder), and showing the most recent files.

If you want specific files to no longer being the the most recently opened files, you would typically open other files. They would then become the most recently opened files - and eventually the unwanted files would disappear from the list. Another option is to change the "Last Opened" time on those unwanted files, so that they are no longer at the top of the list.

Getting a bit more technical, the "Last Opened" time shown in Finder is actually stored on disk as the file system meta data attribute "kMDItemLastUsedDate". This value is automatically updated by LaunchServices when you either double-click a file, or some application asks LaunchServices to open that file on your behalf.

You can view the "LastOpened" time of a particular file using the Terminal by running a command like this:

mdls -name kMDItemLastUsedDate ~/Desktop/TheFileIWant

Note that not all files have such an attribute. Also note that is not that easy to actually change that attribute.

If you for example look at the attribute in Terminal using the xattr command, you'll find that there it is named "com.apple.lastuseddate#PS" with #PS" meaning that the attribute "sticks" to the file when it is copied or synced. Just copying the file alone won't remove the last used date from it - the timestamp would be copied along with the file contents.

You can delete the attribute from the file like this:

xattr -d com.apple.lastuseddate#PS myfile

However, the attribute is still shown in Finder, and so the file still appears in the Recents folder.

A "somewhat simple" way of getting a file out of the Recents folder is actually to copy it in the Terminal using the cp -X command, which copies the file without the metadata attributes. You would then remove the old file and rename the copy back to the original name. As an example a file named myfile.wav could have its last used attribute removed like this:

cp -X myfile.wav myfile.wav.copy
rm myfile.wav
mv myfile.wav.copy myfile.wav

Note: This also removes other attributes on the file - so be careful if there's something there you want to preserve.

If you want to delve even more into the technical details of the "Recents" folder, you should note that the folder in Finder is actually simply a saved Spotlight query. You can review the saved searches used by Finder by opening this folder in Finder (by using the Go menu in Finder and choosing "Go to Folder..."):

/System/Library/CoreServices/Finder.app/Contents/Resources/MyLibraries

Inside, you'll find a saved search named "Recents" which is really what the Recents folder "is". Using the Terminal, you can review the definition of that saved search like this:

less /System/Library/CoreServices/Finder.app/Contents/Resources/MyLibraries/myDocuments.cannedSearch/Resources/search.savedSearch

In theory you could alter this saved search to exclude the files you want to keep out of the list. In practice, you probably want to mess with system files for such a task. Depending on the macOS version you're running, editing system files could be relatively complicated as well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .