Can Mac OS X's Spotlight be configured to ignore certain file types? [closed]
Asked Answered
L

4

6

I've got bunches of auxiliary files that are generated by code and LaTeX documents that I dearly wish would not be suggested by SpotLight as potential search candidates. I'm not looking for example.log, I'm looking for example.tex!

So can Spotlight be configured to ignore, say, all .log files?

(I know, I know; I should just use QuickSilver instead…)


@diciu That's an interesting answer. The problem in my case is this:

Figure out which importer handles your type of file

I'm not sure if my type of file is handled by any single importer? Since they've all got weird extensions (.aux, .glo, .out, whatever) I think it's improbable that there's an importer that's trying to index them. But because they're plain text they're being picked up as generic files. (Admittedly, I don't know much about Spotlight's indexing, so I might be completely wrong on this.)


@diciu again: TextImporterDontImportList sounds very promising; I'll head off and see if anything comes of it.

Like you say, it does seem like the whole UTI system doesn't really allow not searching for something.


@Raynet Making the files invisible is a good idea actually, albeit relatively tedious for me to set up in the general sense. If worst comes to worst, I might give that a shot (but probably after exhausting other options such as QuickSilver). (Oh, and SetFile requires the Developer Tools, but I'm guessing everyone here has them installed anyway :) )

Leggat answered 3/9, 2008 at 7:27 Comment(1)
You can buy a program like Leap or HoudahSpot to do ninja stuff like this with a UI. Its likely better to leave the items in the database, and just use a better search tool. The Spotlight system fully supports excluding file types, for instance. (or you could use mdfind with things like kMDItemContentType != 'whatever kind you don't want'Haldas
S
3

@Will - these things that define types are called uniform type identifiers.

The problem is they are a combination of extensions (like .txt) and generic types (i.e. public.plain-text matches a txt file without the txt extension based purely on content) so it's not as simple as looking for an extension.

RichText.mdimporter is probably the importer that imports your text file. This should be easily verified by running mdimport in debug mode on one of the files you don't want indexed:

cristi:~ diciu$ echo "All work and no play makes Jack a dull boy" > ~/input.txt
cristi:~ diciu$ mdimport -d 4 -n ~/input.txt 2>&1 | grep Imported
    kMD2008-09-03 12:05:06.342 mdimport[1230:10b] Imported '/Users/diciu/input.txt' of type 'public.plain-text' with plugIn /System/Library/Spotlight/RichText.mdimporter.

The type that matches in my example is public.plain-text.

I've no idea how you actually write an extension-based exception for an UTI (like public.plain-text except anything ending in .log).

Later edit: I've also looked though the RichText mdimporter binary and found a promising string but I can't figure out if it's actually being used (as a preference name or whatever):

cristi:FoodBrowser diciu$ strings /System/Library/Spotlight/RichText.mdimporter/Contents/MacOS/RichText |grep Text

TextImporterDontImportList

Soldierly answered 3/9, 2008 at 9:6 Comment(0)
E
3

Not sure how to do it on a file type level, but you can do it on a folder level:

Source: http://lists.apple.com/archives/spotlight-dev/2008/Jul/msg00007.html

Make spotlight ignore a folder

If you absolutely can't rename the folder because other software depends on it another technique is to go ahead and rename the directory to end in ".noindex", but then create a symlink in the same location pointing to the real location using the original name.

Most software is happy to use the symlink with the original name, but Spotlight ignores symlinks and will note the "real" name ends in *.noindex and will ignore that location.

Perhaps something like:

mv OriginalName OriginalName.noindex ln -s OriginalName.noindex
OriginalName

ls -l

lrwxr-xr-x 1 andy admin 24 Jan 9 2008 OriginalName -> OriginalName.noindex drwxr-xr-x 11 andy admin 374 Jul 11 07:03 Original.noindex

Endemic answered 3/9, 2008 at 7:31 Comment(0)
S
3

@Will - these things that define types are called uniform type identifiers.

The problem is they are a combination of extensions (like .txt) and generic types (i.e. public.plain-text matches a txt file without the txt extension based purely on content) so it's not as simple as looking for an extension.

RichText.mdimporter is probably the importer that imports your text file. This should be easily verified by running mdimport in debug mode on one of the files you don't want indexed:

cristi:~ diciu$ echo "All work and no play makes Jack a dull boy" > ~/input.txt
cristi:~ diciu$ mdimport -d 4 -n ~/input.txt 2>&1 | grep Imported
    kMD2008-09-03 12:05:06.342 mdimport[1230:10b] Imported '/Users/diciu/input.txt' of type 'public.plain-text' with plugIn /System/Library/Spotlight/RichText.mdimporter.

The type that matches in my example is public.plain-text.

I've no idea how you actually write an extension-based exception for an UTI (like public.plain-text except anything ending in .log).

Later edit: I've also looked though the RichText mdimporter binary and found a promising string but I can't figure out if it's actually being used (as a preference name or whatever):

cristi:FoodBrowser diciu$ strings /System/Library/Spotlight/RichText.mdimporter/Contents/MacOS/RichText |grep Text

TextImporterDontImportList

Soldierly answered 3/9, 2008 at 9:6 Comment(0)
S
2

Here's how it might work.

Note: this is not a very good solution as a system update will overwrite changes you will perform.

Get a list of all importers

cristi:~ diciu$ mdimport -L
2008-09-03 10:42:27.144 mdimport[727:10b] Paths: id(501) (
    "/System/Library/Spotlight/Audio.mdimporter",
    "/System/Library/Spotlight/Chat.mdimporter",
    "/Developer/Applications/Xcode.app/Contents/Library/Spotlight/SourceCode.mdimporter",

Figure out which importer handles your type of file (example for the Audio importer):

cristi:~ diciu$ cat /System/Library/Spotlight/Audio.mdimporter/Contents/Info.plist 




[..]
            CFBundleTypeRole
            MDImporter
            LSItemContentTypes
            
                public.mp3
                public.aifc-audio
                public.aiff-audio

Alter the importer's plist to delete the type you want to ignore.

Reimport the importer's types so the system picks up the change:

mdimport -r /System/Library/Spotlight/Chat.mdimporter
Soldierly answered 3/9, 2008 at 7:48 Comment(0)
T
1

The only option probably is to have them not indexed by spotlight as from some reason you cannot do negative searches. You can search for files with specifix file extension, but you cannot not search for ones that don't match.

You could try making those files invisible for Finder, Spotlight won't index invisible files. Command for setting the kIsInvisible flag on files is:

SetFile -a v [filename(s)]

Tresa answered 3/9, 2008 at 9:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.