Getting Back to (Search) Basics

NOTE: A new and improved version of this script has been posted. Please use the new version. It's way better.

First, a few brief DISCLAIMERS:
1. The information and script provided in this post will disable Spotlight indexing.
2. It will also (optionally) erase your Spotlight index.
3. This means that if you want to re-enable Spotlight indexing, you will have to wait for the index to rebuild, which can take a long time.
4. This method only disables Spotlight indexing for firewire drives that are present when the script is run. Once a firewire drive has had Spotlight disabled, it will be disabled forevermore on all systems, as the indexing status of any given volume is stored on the volume itself.
5. Finally, it has come to my attention that using this script to disable Spotlight indexing will also disable searching by "Entire Contents" in Apple's Mail app. (Searching by "From," "To," and "Subject" all work fine.) This is a major drawback for some, and less so for others, but it's something you should be aware of before you proceed to disable Spotlight indexing on your system. If you can't live without Mail searches by content, do not use the script at the end of this post.

These are the only issues I am aware of regarding this script. If you discover others, please post them in the comments section.

And away we go!

I really miss the old Panther-style, find-by-name searches. (And apparently so do a lot of people!) I use them much more than the Tiger method of searching by metadata and file content, which just returns way too many results for my tastes, generally speaking. (I mean, if you don't know the name of your file, how do you know you've found it anyway, right?)

Ideally, Apple would have (or still will, I hope) given us some options here. I think it would be best if searches from the toolbar functioned as they did in Panther (i.e. quick 'n' dirty seach-by-name-in-current-folder) or there were a preference for how toolbar searches work. Spotlight searches should function differently, based on the metadata concept. That's basically how I think it should work: two search methods; two types of results. And bring back the old Finder toolbar search. I love(d) that thing!

That said, I've spent some time researching the matter, looking for a way to get back search-by-name functionality, since, if I have to choose between one way or the other (and right now it looks like I do), I choose to search by file name. I found some tasty info on Apple's Tiger discussion forums which I will briefly outline:

1. Moving all volumes to the "Privacy" tab of Spotlight's preferences will disable Spotlight. However, you will then lose the ability to find files at all -- by name or otherwise -- in the Finder. Also, if you mount an external drive, Spotlight will try to index it until you then add it to the "Privacy" tab. Not the best solution.

2. Spotlight can be completely disabled by simply adding the line:
SPOTLIGHT=-NO-
to your /etc/hostconfig file and rebooting. This method is very thorough, it seems. Drives later added to the system will never be indexed. Spotlight won't even try. Unfortunately, this method again has the side effect of rendering all disks unsearchable from the Finder. Not what I'm looking for.

3. Enter mdutil. (And, BTW, I want to credit Ondrej Zacek from the Apple Discussions. Though the info is freely available, it was his "Finder will fall back to old behavior when searching..." comment that gave me hope. Thanks, dude, whoever you are.) Using mdutil to disable Spotlight indexing on a given volume results in Finder and Spotlight behavior I can live with. Essentially, that is, after you've disabled indexing with mdutil, you can search files in the Finder or with Spotlight, and the results returned will only be ones that include your search term in the file name. And in Spotlight searches, you still get the extra added benefit of having things sorted by type (somehow Spotlight can still identify and sort files by type, even if the search is only by name).

Now that's pretty durned cool. I have the ability to search by name (only) again, and I still get some of the usefulness of Spotlight. (And, P.S., Finder toolbar searches will also be sorted by kind. A simple window style change to list view -- or command-2 -- will get you the flat list you're used to.)

Anyway, here is the one command that will disable Spotlight on ALL your volumes:
sudo mdutil -i off / /Volumes/*

Additionally, you might want to remove the existing databases from all volumes as well, for good measure:
sudo mdutil -E / /Volumes/*

NOTE: Before you run either of these, be aware that if you want to reverse this process you can, but you will have to wait for Spotlight to reindex all your volumes again, and this can take a looong time. Also, if you add an external firewire drive, Spotlight will try to index it. Running these commands will stop it, however.

And, so, to reverse the process:
sudo mdutil -i on / /Volumes/*

A few seconds after running this, Spotlight will begin reindexing.

Finally, some scripting goodness. I wrote a simple shell script that automates all of this. It has options for both enabling and disabling Spotlight metadata searching. Feel free to use it, or modify it, to your heart's content. Ideally there would be a way to run the mdutil commands whenever a firewire drive is mounted, but I haven't tried that yet. In any case, this works really well for me at this point. Hopefully someone else will find it useful as well.

To use this script, open TextEdit (in the standard Rich Text mode, for now) copy the text below "Begin Shell Script" (starting with #!/bin/bash) into a new text file, and then convert this file to plain text (Format->Make Plain Text). Name it, save it, chmod it to 755 (open Terminal, type chmod 755 and then drag the file to the Terminal window and hit return). Finally, drag the file again into the Terminal window, hit return and follow the instructions. Also, if you want to make it double-clickably executable, give the name a .command suffix. Yum!

Hopefully Apple will give us some flexibility in how we search our files in the not-too-distant future. Until then, I'll be using my trusty script and old-world search methods in my shiny new Tiger Finder.

Hmph!

-------------------------
Begin Shell Script
-------------------------
#!/bin/bash

clear

echo "
############# DISABLE OR ENABLE SPOTLIGHT #############"

echo "
This script will enable or disable Spotlight searching
and (optionally) indexing on ALL LOCAL VOLUMES.
Panther-style finds-by-name will still function after
disabling Spotlight using this script.
"

echo "
Choose your poison...

[1] Disable Spotlight
[2] Enable Spotlight
[Ctrl-c] to Quit at any time
"
read poison

if [ $poison = 1 ]
then

echo "

####### DISABLE SPOTLIGHT ROUTINE #######"

echo "
Disabling Spotlight for all volumes...
"
sudo mdutil -i off / /Volumes/*
echo "
Would you also like to erase the Spotlight index (Y/N)?"
read index
if [ $index = y -o $index = Y ]
then
sudo mdutil -E / /Volumes/*
fi
echo "

*********************************************

Spotlight search is no longer in effect.
You may now search by file name only.

Have fun with your Tiger, Tiger.

*********************************************

"
exit 0

else
if [ $poison = 2 ]
then
echo "

####### ENABLE SPOTLIGHT ROUTINE #######"

echo "
Enabling Spotlight for all volumes...
"
sudo mdutil -i on / /Volumes/*
echo "

* ********************************************

Spotlight has been enabled on all volumes.
Indexing should begin momentarily.
It may take quite some time to complete.

Have fun with your Tiger, Tiger.

*********************************************

"

else
echo "
You did not choose from the available options.
Please rerun the script to try again.
"
fi
fi

exit 0

-------------------------
End Shell Script
-------------------------