Mac OS X 的 Spotlight 可以配置为忽略某些文件类型吗?

发布于 2024-07-04 06:50:45 字数 1476 浏览 7 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

终难遇 2024-07-11 06:50:45

不确定如何在文件类型级别执行此操作,但您可以在文件夹级别执行此操作:

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

使聚光灯忽略文件夹

如果您绝对不能重命名该文件夹,因为其他软件依赖于它另一种技术是继续将目录重命名为以“.noindex”结尾,但然后在同一位置创建一个符号链接,指向使用原始名称的真实位置。

大多数软件都乐意使用带有原始名称的符号链接,但 Spotlight 会忽略符号链接,并会注意到“真实”名称以 *.noindex 结尾,并且会忽略该位置。

也许是这样的:

mv OriginalName OriginalName.noindex
ln -s OriginalName.noindex
原名

ls-l

lrwxr-xr-x 1 安迪 管理员 2008 年 1 月 9 日 24 日
原始名称 -> 原始名称.noindex
drwxr-xr-x 11 安迪管理员 374 七月 11
07:03 原创.noindex

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

也只是曾经 2024-07-11 06:50:45

以下是它可能的工作原理。

注意:这不是一个很好的解决方案,因为系统更新覆盖您将执行的更改。

获取所有导入器的列表

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",

找出哪个导入器处理您的文件类型(音频导入器的示例):

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




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

更改导入器的 plist 以删除您想要忽略的类型。

重新导入导入程序的类型,以便系统接收更改:

mdimport -r /System/Library/Spotlight/Chat.mdimporter

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
遗失的美好 2024-07-11 06:50:45

@Will - 这些定义类型的东西称为统一类型标识符

问题是它们是扩展名(如 .txt)和通用类型(即 public.plain-text 纯粹根据内容匹配没有 txt 扩展名的 txt 文件)的组合,因此它不像查找扩展名那么简单。

RichText.mdimporter可能是导入文本文件的导入器。
这应该可以通过在调试模式下对您不想索引的文件之一运行 mdimport 来轻松验证:

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.

在我的示例中匹配的类型是 public.plain-text。

我不知道你实际上如何为 UTI 编写基于扩展的异常(例如 public.plain-text,除了以 .log 结尾的任何内容)。

稍后编辑:我还查看了 RichText mdimporter 二进制文件,发现了一个有希望的字符串,但我无法确定它是否实际被使用(作为首选项名称或其他名称):

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

TextImporterDontImportList

@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

南七夏 2024-07-11 06:50:45

唯一的选择可能是不让它们被聚光灯索引,因为由于某种原因你不能进行负面搜索。 您可以搜索具有specifix 文件扩展名的文件,但不能不搜索不匹配的文件。

您可以尝试使这些文件对 Finder 不可见,Spotlight 不会索引不可见文件。 在文件上设置 kIsInvisible 标志的命令是:

SetFile -av [文件名]

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)]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文