0

When using the search box in a Finder window, I would like to configure Spotlight so that a search will follow symlinks in the directory tree below the folder being searched.

For example, I symlinked several folders from my Home directory to a different drive, including Documents. When I start a search from my Home directory, the results will not include those from Documents if I limit the search to my Home directory. The results do show up if I choose the search location as "This Mac", but I would like them to show up in a search limited to my Home directory.

Alternatively, the problem might be solved by performing a search of multiple directories at once.

I have found that using Finder aliases rather than symlinks is not a solution to the problem, since Finder doesn't follow aliases either.

3

2 Answers 2

1

Finder's Spotlight search interface is somewhat limited - as you have discovered.

Is there a way? With third party software, Yes! And no need for symlinks, etc.

I suggest you try HoudahSpot. With HoudahSpot you can specify which locations (disks or folders) you want included in a search. You can create templates for different locations and search details.

HoudahSpot does not create its own search index, rather it uses the indexes created for Spotlight. It is a more powerful interface for searching the Spotlight indexes.

The developer, posted a reply to a related question How to search multiple spotlight sources / drives simultaneously?

4
  • That looks interesting -- would this allow a usage in which you simply search a directory (e.g. home folder), and the search will follow symlinks in the directory tree and include those results? Commented Jun 25, 2022 at 16:10
  • No, this will not follow symlinks. I am suggesting that you don't need to follow symlinks if you a way of selecting multiple disks/folders for a search. Finder search does not allow you to choose multiple specific disks/folders. But HS does. So in HS you can specify your home directory plus all the other folders you want included in your searches. Try it.
    – Gilby
    Commented Jun 25, 2022 at 23:18
  • OK, that could work well, particularly if the search could be bookmarked, e.g. in the finder sidebar Commented Jun 26, 2022 at 18:44
  • HS uses 'template' searches (like bookmarks). You can create your own templates and they reside in the HS sidebar.
    – Gilby
    Commented Jun 26, 2022 at 23:09
0

Make Spotlight search multiple paths by editing a saved search

It is possible to get Spotlight to search multiple directories at once, but it requires creating a saved search (smart folder), and then manually editing the .savedSearch XML file:

  1. In Finder, navigate to one of the directories you want to search, and click File > New Smart Folder.
  2. To keep the queury as general as possible, you can move to step 3 now and add your search terms and conditions when you perform the actual search later. If, on the other hand, you want a narrower search any time you use this saved search in the future, you can type a search term in the search box and/or add conditions using the '+' icon underneath it.
  3. Hit the save button below the search box, and check the option box to add a shortcut to the query to Finder's sidebar. The default save path is in your ~/Library, but I'm using an alternate path in my Documents folder so the file isn't buried and forgotten in the future. Keep the file extension as savedSearch -- the file name I used was Multi-Search.savedSearch, but this can be changed easily later.
  4. Now I've got a Multi-Search sidebar item, but it's not that useful yet. Open the .savedSearch file in a text editor (e.g. textEdit.app or VS-Code). You will now be looking at an XML file with 200+ lines, but we only need to make a small edit.
  5. The path to the directory where we created our search is written in 3 different places in the file: within SearchScopes, CurrentFolderPath, and FXScopeArrayOfPaths. We can leave SearchScopes and CurrentFolderPath alone, but we need to edit the FXScopeArrayOfPaths array to add the additional directories we want to search. Below the FXScopeArrayOfPaths key, copy the full line with the <string>...</string> tags and paste on a new line below (i.e. your new line should include the <string> tags and be within the <array> tags). Now edit the line you pasted to point to an additional path you want to search. Repeat if you want to search more paths.
  6. Save the XML file. To change the name of the sidebar shortcut to this query, just edit the file name of the .savedSearch file. To activate the new functionality from the savedSearch, it is necessary to relaunch the Finder: hold option and right-click the Finder icon in the Dock, then choose Relaunch.
  7. To use the search, click the icon in the sidebar of a Finder window, and type or search terms, or add conditions with the '+' icon as usual.

Notes:

  • If you originally added as search string before creating the saved search, and you now want to remove it so it doesn't apply to all future searches, strip it from the XML by looking for the RawQuery key, and replacing its string with <string>false</string>. The key occurs in 2 places. Also remove the FXCriteriaSlices key and the array that follows it.
  • This answer suggests there's also a way to exclude paths from a search, by adding a dash in front of (full) paths in the arrays.

Sources: macsales.com article and this video.

You must log in to answer this question.

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