Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

10.4: Some Spotlight tips and tricks System 10.4
Tiger only hintSpotLight uses a database at the backend. If the database is corrupted and you want to rebuild it (or if you just want to force a rebuild), you can do so:

In SpotLight system preferences, go to the Privacy tab and drag and drop the volume you want to re-index into the table. That will erase the index of that volume, as you've asked it to now be non-searchable. Just remove the volume from the table, and indexing will re-start and create a new database. This can also be achieved in the Terminal by using the following command:
sudo mdutil -E /path/to/volume
For example, sudo mdutil -E / will erase the boot volume database. See man mdutil for more options. Read the rest for some more advanced Terminal and Spotlight tips...

Advanced Searching:

While Apple provides an interface to do searches, it has some limitations. If you need to use more customized searches, you can do so either in the Terminal, or in a search window using Raw requests criteria (do a Finder Find, click Other, then Raw Query from the pop-up). The key commands are mdls, which allows you to list the metadata of a file, and mdfind, which actually performs searches. See the man pages for both commands to get more details. The interesting part is that mdfind actually supports logical operators (and, or, not, etc...), which can help to create advanced requests.

An additional way to find informations on how to write requests is to read the information in the finder of a Smart Folder (created by saving a search; do a Get Info on it). You will find the request sent to Spotlight, and can use that information to create your own searches.

Examples of requests:
$ mdfind -onlyin ~ "(kMDItemFSName =='*.htm*') && (kMDItemFSName !='*Favorites*')"
  /* Find all the files containing '.htm' but not 'Favorites' in your home folder */

$ mdfind -onlyin ~/Desktop/Test "kMDItemContentTypeTree = 'public.text'" 
  /* Find all Text documents in the Test folder of your Desktop folder */

$ mdfind "kMDItemFSLabel != '6'"
  /* Find files that are not labeled '6' (one of the available colors of labels) */
As you can see, you can do quite a bit with a raw-style query that you may not be able to do so easily via the GUI.
    •    
  • Currently 5.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[35,831 views]  

10.4: Some Spotlight tips and tricks | 13 comments | Create New Account
Click here to return to the '10.4: Some Spotlight tips and tricks' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
10.4: Some Spotlight tips and tricks
Authored by: chrobb on Mon, May 2 2005 at 3:55PM PDT
Has anyone figured out a way to enter these queries in the Spotlight search stick? I can't believe that Apple would provide no way to do it via a debug directive or some escape characters.

[ Reply to This | # ]
10.4: Some Spotlight tips and tricks
Authored by: maartensneep on Mon, May 2 2005 at 5:26PM PDT
Open a Find window in the Finder (cmd-F), select 'other' at the bottom of the list, type 'raw' in the search box, select the item that remains and you get the same syntax in the GUI.

Maarten

[ Reply to This | # ]
10.4: Some Spotlight tips and tricks
Authored by: chrobb on Mon, May 2 2005 at 5:43PM PDT
Yes, I see that. What I want to do is access the raw search capabilities without going through those steps. Why can't I type that query in the Spotlight menu. It wouldn't hurt the user experience in any way and would only enhance things for power users.

[ Reply to This | # ]
10.4: Some Spotlight tips and tricks
Authored by: token25 on Mon, May 2 2005 at 6:34PM PDT
Is there any way to completely remove the spotlight menu from the menu bar? The keyboard short cut is enough for me, and I don't really want that manu cluttering up my menu bar. Any ideas?

[ Reply to This | # ]
10.4: Some Spotlight tips and tricks
Authored by: ahknight on Tue, May 3 2005 at 12:35AM PDT
Shamelessly copied from Ars Technica and Mac Geekery. You should at least credit your sources.

[ Reply to This | # ]
10.4: Some Spotlight tips and tricks
Authored by: Gremlins on Tue, May 3 2005 at 1:06PM PDT
Hummm. I actually sent these tips before the articles on Ars Technica and Mac Geekery were published. Now, that information (at least on the advanced searching) is part of the Apple Developper tool to which, as far as I remember, I linked when sending the tips.
http://developer.apple.com/macosx/tiger/spotlight.html

If it is not enough to convince you, I also posted these infos on wikitosh on the 27th (Arstechnica article :28th, Mac Geekery article: 30th

Ashamed ? No, not really :) I suppose that this type of information is important enough to generate a lot of posting all over the place...

[ Reply to This | # ]
10.4: Some Spotlight tips and tricks
Authored by: belette on Tue, May 3 2005 at 7:24AM PDT
Great!! I was wondering if there was a way to do this. I even asked on some french mac forums but nobody seemed interested by the question...

Anyway. I'd like to do a search containing every element whose kMDItemKind is "application" that is NOT in my user directory. I can't use the "onlyin" trig, of course. Is there an information about the path to the element that i could use?

[ Reply to This | # ]
10.4: Some Spotlight tips and tricks
Authored by: iloveitaly on Tue, May 3 2005 at 10:17AM PDT
Is there a way to get the path of a file? I want to exclude all files that are in the trash. Looking through the ADC dev articles their is not a metadata attribute that contains the path of the file, am i missing something?

[ Reply to This | # ]
10.4: Some Spotlight tips and tricks
Authored by: belette on Sat, May 7 2005 at 5:51AM PDT
There is a "kMDItemPath" attribute, but i can't seem to be able to do anything with it... Any idea?

[ Reply to This | # ]
10.4: Some Spotlight tips and tricks
Authored by: brising on Wed, May 4 2005 at 10:02AM PDT
Nice hint. One little fix in the examples, though. The last example has
kMDItemFSLabel != '6'
The labels are numeric, not string-valued, so this should be
kMDItemFSLabel != 6
Using the string value caused my disk to start churning and the Finder to hang, requiring a force-quit of the Finder.

[ Reply to This | # ]
Boolean search is possible in Spotlight
Authored by: HiramNL on Wed, May 4 2005 at 11:36AM PDT
For some mysterious reason, a hint I submitted to MacOSXHints yesterday, explaining how to use (undocumented) boolean search options in Spotlight, was never published. I'll limit myself to linking to my two articles about the matter, found here and here.

[ Reply to This | # ]
10.4: Some Spotlight tips and tricks
Authored by: neodidymos on Sat, May 7 2005 at 11:33AM PDT
Any thoughts on how to EXCLUDE "Trash" from being searched/indexed? I added Trash folder to the "Privacy" tab (had to drag it in and it added /Users/username/.Trash. I saved the preferences and closed it.

Opened it back up and it was removed. Looks like it doesnt like ".Trash" hidden folder being included in the privacy option.

[ Reply to This | # ]
10.4: Some Spotlight tips and tricks
Authored by: jacobolus on Tue, Jan 24 2006 at 3:34PM PST
I think it should be unindexed by default, given that every file/folder starting with a "." gets left unindexed.

[ Reply to This | # ]