Spotlight and iCloud Drive in Sierra

Last year, I wrote here that Spotlight search should work on files stored in iCloud Drive, under macOS Sierra, unless you make your iCloud Drive an excluded drive from Spotlight’s indexing. Since then, Tom Eriksen commented that, in his experience, that wasn’t the case, and that when files are moved to iCloud Drive, and removed from local storage, they are lost to Spotlight search.

If that was the case, it would be a major blow to Apple’s Optimized Storage scheme in Sierra: when macOS decides to move your least-used documents to iCloud to free up local storage, it would also take them out of range of Spotlight. So I thought that this might be worth re-examining more thoroughly.

A simple functional test

If you ever want to check whether Spotlight is working – or, for example, whether it is respecting a folder which you have excluded from indexing – the best thing to do is create a text document containing a word which is very unlikely to appear in any other file in your storage, local or cloud. My choice was prestidigitation, which I don’t use very often, especially when drunk.

So I created a TextEdit text file with a little text padding, and the magic word, the needle I’m going to place in iCloud’s haystack. I then moved that file to my iCloud Drive, ensuring that it was removed from local storage. I left it for a couple of hours, then ran a Spotlight search on the word. Sure enough, Spotlight found it in that document on my iCloud Drive.

spotlighticloud

This doesn’t prove that Spotlight also works on documents which are moved by macOS under the Optimized Storage scheme, but it demonstrates that it does index at least some files stored there.

If you ever want to check Spotlight’s function anywhere else, simply get it to hunt a similar needle in the haystack of your storage.

Looking for index folders

Another way of telling whether Spotlight has indexed any particular volume is to look for its metadata index folder on that volume. As this is a hidden folder, the best way to do this is in Terminal.

One of the peculiarities of iCloud Drive is that it is not mounted in a regular Unix way, in the /Volumes folder, but in a special folder named Mobile Documents in your Home Library folder (~/Library/Mobile Documents). List any storage mounted in /Volumes using ls -la, and you’ll see the characteristic top-level folder on that volume which contains Spotlight’s indexes:
drwx------ 5 hoakley staff - 170 24 Sep 2012 .Spotlight-V100
for example.

Look inside the Mobile Documents folder, and there is no folder containing metadata indexes. There is, though, a folder named com~apple~system~spotlight, but that doesn’t look like a .Spotlight-V100 folder, and here doesn’t even contain any files or data. So however Spotlight found my crafted text file, it wasn’t through its normal index system.

Looking for the top-level .Spotlight-V100 index folder is a good way of checking that Spotlight has built its indexes on any given volume, although if the contents of the volume are excluded from indexing, there might not be any indexes there, of course.

Looking for indexing taking place

The background process which performs indexing for Spotlight is named mdworker. At any moment, there are several instances of mdworker likely to be running on your Mac – I have seven here at present. When you have just made changes to the contents of storage, such as your iCloud Drive, an mdworker process should swoop down and index all changed and new files.

spotlightmdworker

You may be able to pick this up in the logs. I set LogLogger 5b to look for the pattern of
processImagePath CONTAINS(c) mdworker
over the last couple of minutes, and got plenty of successful hits giving details about indexing activity. But I think that you’d have to be quite lucky to catch an mdworker process working on files in your iCloud Drive.

Optimized Storage

I don’t know whether any or all of the above also applies to Sierra’s Optimized Storage. But if you use iCloud Drive to store documents which you want included in Spotlight searches, or if you have enabled Optimized Storage and some of your documents have now been moved to iCloud, you might like to run the simple functional test, to confirm whether your cloud documents do still get included in Spotlight search.

I’d be fascinated to hear of your results here, please.