Is there some way to use the Saved Search capability of the OSX finder to create a virtual union directory? I've made it two-thirds of the way to a solution:
We want everything in the union-ed directories to display in the virtual directory. However, normally, you must specify some sort of query parameter when composing a search; if you create a search by typing into the Search field, then removing what you've typed, then saving the resulting search, that Saved Search will have no results. This is because the RawQuery in the Saved Search file is simply set to
false. If you change this to
true, you will see all possible results within the folder.
Normally, the Finder only allows you to specify a single directory to return search results from—if you want to search three separate directories, you usually specify the shared parent to all those folders (even if that means you end up having to specify /). However, in the Saved Search file format itself, the "scope" of your query is actually an array of directories—so to search multiple directories, you simply have to add multiple items to that array. (Well, technically, two redundant arrays: SearchScopes and FXScopeArrayOfPaths. However, the second is only used for rendering the scope when editing the query in the Finder.)
The last problem is that that doing this will recursively search the resulting directories—so, if you have a folder within one of the result directories, you'll see the folder in the results, but also all of its contents. Obviously this isn't how real union directories work; what we really want is something similar to a
--max-depth parameter, so we only see the files and folders directly within each of the union-ed directories. Is there some way to accomplish this?