On 26 Sep 2015, at 11:59 AM, Christopher Stone <email@hidden> wrote:
Searching ~/ with `tag` generates 614 listings and takes about 2 minutes.
tag -m Red -d ~/
Spotlight finds 610 with tag:red.
OK, I see why we're getting different results. tag only uses Spotlight when you specify --find; using -m it does its own recursive search, using code a bit like that you posted last week, rather than Spotlight APIs.
So the equivalent of this:
my searchInListOfPaths:{(current application's NSMetadataQueryUserHomeScope)} forTags:{"Red"}
would be:
do shell script "/path/to/tag --find Red --home"
Now they should both return the same number of entries.
The problem is that the Spotlight API is designed for, well, Spotlight, and it's asynchronous. So you start a search, and quick as a flash it notifies you of an initial bach of finds. Then periodically it may notify you with more matches. You can often see this happening in the Finder: it looks faster than it is because it quickly gives you something to look at, and the list gets updated (about once a second, by default). But this sort of thing doesn't lend itself to synchronous approaches like AppleScript or command-line tools.
So my script and tag are both only getting the result of the initial gather. In theory, they should hang in there, adding any updates, and not return until the query says it's completely finished. The problems with that are that (a) it's going to be slower, (b) it's trickier to do in a synchronous manner, and (c) in the ASObjC version at least, it's not working for me :-( When I get a chance, I'll see if I can update the tag code to see if it works there.
And I'd be curious to see what mdfind returns. I can't seem to come up with the right equivalent incantation.
Meanwhile no-one should rely on either the code I posted or tag's --find method. If anyone's interested, I can post a recursive search method.
|