Determining whether mdworker (Spotlight) has completed first scan
Asked Answered
H

1

6

How do I determine that mdworker (Spotlight) has completed its first scan? I'm basically looking for the point at which the little "." in the spotlight search icon would go away and you'd be able to perform searches. (Obviously the OS has a way to determine this since it displays a dot until it's ready...) I'm not seeing anything from mdutil and I can't find anything in the Spotlight APIs.

I'm currently forcing my own scan synchronously using mdimport, but this introduces a long delay (from minutes to hours depending on how aggressive I'm being about where to search) and duplicates work that mdworker is already doing.

Any solution (programmatic, scripted, documented, or undocumented) is fair game here.

Haemophilic answered 3/1, 2012 at 20:26 Comment(0)
H
1

I opened a DTS for this with Apple. The answer is that there is no supported way to do this as of 10.7. The "little dot" that the spotlight search icon uses is controlled with a private interface.

My goal has been to get an inventory of installed applications.

My solution currently is to gather a list of all the apps in /Applications using fts and searching for things named ".app", and pruning as I go so I don't get sub-applications. (This would be easier to do with NSDirectoryEnumeration, but this particular piece of code is in C++ with Core Foundation. It would be easier to do with CFURLEnumerator, but I need to support 10.4. So fts is fine.)

Scanning for this list is very fast. Once I know the minimum number of apps on the box, I compare that to what system_profiler outputs. If system_profiler tells me that there are fewer apps than I know are in /Applications, then I scan all the bundles myself. Otherwise, I use the output from system_profiler.

This isn't ideal, but it's a decent heuristic, is "mostly" right, and prevents drastic underreporting of applications.

Haemophilic answered 31/3, 2012 at 15:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.