Spotlight just kinda’ works. Except when it doesn’t. Which is luckily pretty rare, for the use cases that Spotlight was designed for. But when it doesn’t work, you have a few tools that I’ve highlighted over the years to help you out, including articles on shared volumes, manually indexing, disabling Spotlight, and a few others. But what if you need to go in more depth to isolate an issue? For this, Apple has provided us with a tool called mddiagnose, in /usr/bin. In the following command, we’ll run an mddiagnose to dump a bunch of system statistics that we can then look at. Here, we’ll do that to a folder called test in our current working directory:
/usr/bin/mddiagnose -f test
The output is then test.mdsdiagnostic, a directory with a CrashReporter, spindump, Samples, DiagnosticReports, a few system.log exports, and a diagnostic.log.
You can then view your log using the more command (or cat or less or whatevers)
Here, you’ll see the output of a bunch of scripts that were run. I find that this is the most informational aspect of what I get from the mddiagnose output. Every time I’ve actually fixed an issue here, it’s been with this output.
The other aspect of mddiagnose that I’ve found useful is checking permissions and paths. Here, you can answer the simple question of whether mdutil has permissions to check a path. We’ll do so using the -p option:
mddiagnose -p /Library/Application\ Support/Appifitizer
krypted December 15th, 2015
Looks like I’m on the back page of the latest issue of MacTech Magazine (see Table of Contents at http://www.mactech.com/issue-TOCs-2012). And it turns out I’m not there for the reason I usually adorn the back page of magazines; I’m fully clothed and for the most part it’s technical: I’m the MacTech Spotlight. If I keep this up, I’ll be able to keep my clothes on full time in the future. Not sure what will happen to my spot at Sunset and LaBrea now, though…
Anyway, despite featuring me, MacTech is a great magazine. Where else can you find information on Adobe packaging, QuickLook development, building a Squid proxy, HTML5 and CSS3 design, OpenBSM, keeping nasty network attacks out of Mountain Lion and AppleScriptObjC. I mean seriously, great stuff!
krypted December 12th, 2012
When you search for files the Finder window with the results has what is known as the Path Bar. As you can see in the below image, the Path Bar allows you to click on any directory in the hierarchy up to the one you are on and open that directory in the Finder.
By default, the Path Bar is only shown in a search result, but if you like it then you can see it in every Finder window. To enable this feature, create a boolean key in the com.apple.finder.plist with a value of yes. To do so, you can use the defaults command:
defaults write com.apple.finder ShowPathBar -bool YES
To go back to having the Path Bar disabled:
defaults write com.apple.finder ShowPathBar -bool NO
krypted February 4th, 2010
Posted In: Mac OS X
Spotlight has had a pretty checkered past with Xsan. But things are looking a little better and if you want to try enabling it again, once you’ve fully updated to 2.2 you can do so without too much fanfare. Simply locate the config file for the name of the volume you wish to enable spotlight for, which is in /Library/FileSystems/Xsan/config and is named with the name of the volume followed by a .cfg file extension. Once located, open the file in your favorite text editor (ie – pico, vi, etc). Then, locate the entry for EnableSpotlight, which should be set to No. Change the No to a Yes.
You can also enable two different levels of searching:
To enable either, simply add a line below EnableSpotlight that reads similar to the following (based on the level of indexing you are comfortable with), starting with SpotLightSearchLevel and ending with the type of search you would like to perform:
Once enabled restart the service. While you shouldn’t, you may need to run mdutil (although you shouldn’t have to any more, but I’ve had to a couple of times) to get the spotlight indexing process kicked off. To do so run the mdutil command with the -E option, as you can see here (assuming a volume name of NAMEOFVOLUME):
mdutil -E /Volumes/NAMEOFVOLUME
You can then check the status of the indexing process using the -s option with mdutil, as follows(assuming a volume name of NAMEOFVOLUME):
mdutil -s /Volumes/NAMEOFVOLUME
mdimport -f /Volumes/NAMEOFVOLUME/MYPROJECTNAME
rm -ri /Volumes/NAMEOFVOLUME/.Spotlight-V100
Finally, if you wish to programmatically check that files have been indexed, you can use the mdfind command. This is especially helpful when comparing the results from an Xsan client and the current metadata controller in your environment.
krypted October 8th, 2009
Posted In: Xsan
Whether it’s an Xsan with a wacky mdworker thread, a regular old box trying to scan a whole bunch of files you want it to skip or even a directory that you want to keep private, you can tell Spotlight not to scan a specified folder on your system. Simply use the following command, with the working directory of the shell as whatever directory you want skipped:
In other words, create a file called .metadata_never_index in a folder and Spotlight will skip it. This isn’t to say it skips subfolders…
krypted August 28th, 2009
Spotlight has a nifty integration of keystrokes (or the Command keystroke at least). Simply perform a search and then use the Command key in combination with an arrow to move and up and down in search results based on section rather than line item. Additionally, that Command key can be used in conjunction with the Enter key so that when you open an item in the Spotlight results, it actually just displays the directory so you can then open the file in the Finder (and subsequently access other files in those directories as needed).
krypted March 28th, 2009
Posted In: Mac OS X
To Disable Spotlight for Mac OS X you can stop the Spotlight processes from being invoked by launchd. To do so use the following commands:
launchctl unload -w /System/Library/LaunchAgents/com.apple.Spotlight.plist
launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
To re-enable it you would simply load up your launchd processes again like so:
launchctl load -w /System/Library/LaunchAgents/com.apple.Spotlight.plist
launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
krypted November 23rd, 2008
When client systems need to search the server quickly you can enable Spotlight on the Share Points. To enable this, open Server Admin -> File Sharing -> Share Points -> Click the Share Point in question -> Click Share Point -> Check the box for Enable Spotlight -> Click Save.
Then have a nice long steak dinner.
krypted April 28th, 2008