Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,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 2.56 / 5
  You rated: 3 / 5 (9 votes cast)
 
[48,192 views]  

10.4: Some Spotlight tips and tricks | 14 comments | Create New Account
Click here to return to the '10.4: Some Spotlight tips and tricks' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Some Spotlight tips and tricks
Authored by: chrobb on May 02, '05 03:55:36PM

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 May 02, '05 05:26:26PM

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 May 02, '05 05:43:14PM

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 May 02, '05 06:34:33PM

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 May 03, '05 12:35:40AM
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 May 03, '05 01:06:42PM

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 May 03, '05 07:24:57AM

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 May 03, '05 10:17:42AM

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 May 07, '05 05:51:03AM

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: LakeSolon on Apr 18, '13 08:16:06AM
https://developer.apple.com/library/mac/#documentation/Carbon/Reference/MetadataAttributesRef/Reference/CommonAttrs.html Quoth the docs:
This value of this attribute can be retrieved, but can't be used in a query or to sort search results.
Via this stackoverflow Q/A: http://stackoverflow.com/a/1342019/180070

[ Reply to This | # ]
10.4: Some Spotlight tips and tricks
Authored by: brising on May 04, '05 10:02:13AM
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 May 04, '05 11:36:01AM
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 May 07, '05 11:33:21AM

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 Jan 24, '06 03:34:18PM

I think it should be unindexed by default, given that every file/folder starting with a "." gets left unindexed.



[ Reply to This | # ]