Yosemite’s extended search reaches out to Bing, Maps, and more. But how can you get the best out of its local search facility?
Even the most fastidiously organised Mac users need to search, both their own files and the wealth of information on the Internet. OS X’s Spotlight search may have worked better in the past, but remains the most important tool to locate text content on your Mac. In Yosemite its features are enhanced with more remote searches, including Wikipedia entries, websites generally using Bing, iTunes Store content, trending news, and more.
Metadata
For local searches, Spotlight uses metadata as its basis. This metadata is extracted from file types for which your Mac holds a metadata importer specification, enabling the indexing of most text content. This ensures that Spotlight can rapidly identify which documents contain any given search string, by looking through its pre-compiled index, then returning you a list of hits. You browse that list using Quick Look, deciding which to open and investigate further.
Internally OS X uses a brace of tools to accomplish this. Periodically mdworker
scans new and altered files to compile their metadata and add it to the hidden index files, which are tucked inside a top-level folder named .Spotlight-V100 on each mounted volume.
You can check the indexing status of mounted volumes using mdutil
, which manages the metadata stores for Spotlight. The shell command mdutil -s /
tells you whether indexing is enabled on your startup volume, for example, and mdutil -E /
will erase the indexes on your startup volume, forcing them to be rebuilt, a common way to try fixing Spotlight problems.
You can achieve the same in the Spotlight pane in System Preferences: select the Privacy tab, then click the + button to add the volume to the exclusion list. Close the pane, and re-open it to remove the volume from that list using the – button.
Importers
Importers, which have a standard .mdimporter name extension, can be kept in Library/Spotlight folders or individual application bundles, and the shell command mdimport -L
lists all those currently installed.
Note that some popular apps, including Adobe’s Creative Suite, do not ship with importers, excluding their native files from Spotlight searches. mdfind
runs the command line equivalent of a Spotlight search: for instance,
mdfind "kMDItemTextContent == 'MacUser'"
returns a list of all files containing the text ‘MacUser’.
Sometimes forcing the rebuilding of Spotlight’s index files does not fix an issue, and logs shown in Console contain repeated messages about mdimporter
failing to index a specific file. This occurs most commonly with components tucked away inside Library folders, for instance.
You can fix this by replacing the file which is causing mdimporter
grief; if you cannot find an undamaged copy, you may be able to trash the file, or hide it from being indexed by placing it inside a folder whose name ends with ‘.noindex’.
Up to and including Yosemite, regular searches performed in Spotlight are of text content.
Attributes
Finder’s Find command offers extensive customisation of search attributes. To see the long list of attributes available, open a search window in the Finder, select the left drop-down menu in that window, and click on its final ‘Other…’ item. The resulting dialog lists available attributes; checking additional items there will add them to that menu so that you can include them when specifying a search.
For instance you could set your search to look for files whose Authors metadata includes the string ‘MacUser’, and whose text content includes ‘Spotlight’. This is the best technique for searching metadata fields attached to non-textual documents such as images and movies, which do not otherwise appear in hits from Spotlight searches run from the menu bar tool. You can also include Finder tags in searches using the same mechanism.
Technique: Refining Searches
You can narrow search tasks down without resorting to custom search attributes. Text entered in Spotlight’s search box is treated as a series of words separated by the Boolean operator AND
. Thus blue moon
will return all documents whose text contents contain both the words blue
and moon
anywhere.
If you want to use OR
or NOT
operators, you must make those explicit, for example
(blue OR green) AND paint
finds documents with blue
or green
in them, together with the word paint
. The minus sign -
is shorthand for AND NOT
, so
blue -green
returns documents containing blue
but without green
.
You can also limit results to certain kinds of file, specified by the kind:
tag followed by a standard file type name. So kind:application
confines a search to applications, other self-evident kinds being contact, folder, email, event, image, movie, music, audio, pdf, preferences, bookmark, font
, and presentation
.
Authors are specified using the author:
tag, and artists with by:
, whilst date:
is followed by the localised date format plus today
and tomorrow
. Dates are also used with created:
, modified:
, and can take range operators ==, <, >, <=, and >=
. A sophisticated search might use
(author:bloggs OR author:jb) AND kind:document AND modified:<01/01/2014
There are also alternatives to using Spotlight, including free Alfred, with its optional paid-for PowerPack. This lets you exclude folders from search and more extensive customisation.
Updated from the original, which was first published in MacUser volume 30 issue 10, 2014.