How to add files to the Spotlight index?
For some reason, find
returns more results than mdfind
.
How can I make sure these files are added to the Spotlight index?
$ find ~/Library -iname "*org.virtualbox.app.VirtualBox*" -prune 2>&1 | grep -av "Permission denied"
/Users/sunknudsen/Library/Saved Application State/org.virtualbox.app.VirtualBox.savedState
/Users/sunknudsen/Library/Saved Application State/org.virtualbox.app.VirtualBoxVM.savedState
/Users/sunknudsen/Library/Preferences/org.virtualbox.app.VirtualBoxVM.plist
/Users/sunknudsen/Library/Preferences/org.virtualbox.app.VirtualBox.plist
$ mdfind -onlyin ~/Library 'kMDItemFSName == "*org.virtualbox.app.VirtualBox*"'
Solution 1:
Spotlight only processes files it has an importer for the file type and aren't hidden by rule. This folder is excluded by code in Mojave as far as I can tell. In older OS, the Exclusion list was editable in a preference file named VolumeConfiguration.plist and before that, _rules.plist so it was easier for someone technical enough to use the command line to modify an exclusion and make that folder included. I don't think we get this control via the same mechanism now. Apple still lets us exclude arbitrary folders / files, but relaxing their exclusion list to be more inclusive, may not be possible.
If you want to poke at this - the relevant folder is /System/Volumes/Data/.Spotlight-V100
I would use a tool like ag (easily installed with https://brew.sh) to search by name or content rather than using find
in the mean time.
If you check mdls
for the affected files, you can see the various file types these are and possibly find an app that will claim "indexing" for them.
Here's me reproducing that with a Microsoft preference file:
me@Mac-Pro ~ % mdls ~/Library/Preferences/com.microsoft.autoupdate2.plist
kMDItemFSContentChangeDate = 2020-09-19 20:33:07 +0000
kMDItemFSCreationDate = 2020-09-19 20:33:07 +0000
kMDItemFSCreatorCode = ""
kMDItemFSFinderFlags = 0
kMDItemFSHasCustomIcon = 0
kMDItemFSInvisible = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSIsStationery = 0
kMDItemFSLabel = 0
kMDItemFSName = "com.microsoft.autoupdate2.plist"
kMDItemFSNodeCount = 965
kMDItemFSOwnerGroupID = 20
kMDItemFSOwnerUserID = 501
kMDItemFSSize = 965
kMDItemFSTypeCode = ""
me@Mac-Pro ~ % mdfind 'kMDItemFSName == "com.microsoft.autoupdate2.plist"'
me@Mac-Pro ~ % cp -p ~/Library/Preferences/com.microsoft.autoupdate2.plist ~/Desktop
me@Mac-Pro ~ % mdfind 'kMDItemFSName == "com.microsoft.autoupdate2.plist"'
/Users/me/Desktop/com.microsoft.autoupdate2.plist
It's clear Apple has restricted indexing in this directory which is why you can't find preference files in the user Library folder and they show up immediately when copied to your Desktop.