返回顶部
s

spotlight-searchSpotlight搜索

Search files, apps, and metadata on macOS using Spotlight CLI tools (`mdfind`, `mdls`, `mdutil`) with a fallback script for cases where indexing is incomplete. Use when the task is to find documents, PDFs, apps, file paths, or metadata on a Mac, especially for prompts like "spotlight search", "find this file on mac", "search my computer", "find PDFs", "locate an app", or "check file metadata".

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 0.1.2
安全检测
已通过
122
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

spotlight-search

Spotlight 搜索

概述

优先使用 mdfind 进行索引搜索,使用 mdls 检查元数据,仅在诊断索引问题时使用 mdutil。如果 Spotlight 找不到已知文件,请使用附带的回退脚本,而不是每次都手动编写 find 命令。

快速入门

推荐流程:

  1. 1. 使用 mdfind 进行常规搜索。
  2. 当任务涉及元数据而非查找时,使用 mdls。
  3. 当 Spotlight 索引不完整或结果意外为空时,使用 ./scripts/spotlight_search.sh。
  4. 将回退脚本视为文件名/路径匹配器,而非通用 shell 辅助工具。
  5. 仅使用 mdutil 检查索引状态,且仅在用户明确要求进行系统级更改时,才建议重新索引。

bash

查找名称或内容中包含 invoice 的文件


mdfind invoice

查找今天修改过的 PDF 文件

mdfind kind:pdf AND kMDItemContentModificationDate >= $time.today

查找名称中包含 chrome 的应用程序

mdfind kMDItemContentType == com.apple.application-bundle && kMDItemFSName == chromecd

仅在 ~/Documents 目录中搜索

mdfind -onlyin ~/Documents kind:pdf

查看文件的元数据

mdls /path/to/file

对于先尝试 Spotlight 再回退到 find 的混合搜索,请使用附带的脚本:

bash
./scripts/spotlight_search.sh query
./scripts/spotlight_search.sh -t pdf report
./scripts/spotlight_search.sh -d ~/Documents meeting

核心功能

1. 文件搜索

Spotlight 会索引文件内容和元数据,非常适合在记住文件内容关键词时定位文档。

常见模式:

  • - 简单关键词:mdfind quarterly report
  • 按文件类型:mdfind kind:pdf invoice
  • 按扩展名:mdfind kMDItemFSName == *.mdcd
  • 按日期:mdfind kMDItemContentModificationDate >= $time.yesterday
  • 按大小:mdfind kMDItemFSSize > 1000000(大于 1 MB 的文件)

使用场景: 你记得文件内容中的关键词,需要按类型/日期筛选,或希望快速搜索所有已索引的卷。

2. 应用程序搜索

Spotlight 能够识别已安装的应用程序(.app 包),并可通过名称或包标识符进行查找。

示例:

bash

所有应用程序


mdfind kMDItemContentType == com.apple.application-bundle

名称中包含 visual 的应用程序

mdfind kMDItemContentType == com.apple.application-bundle && kMDItemFSName == visualcd

使用场景: 你需要定位已安装的应用程序,验证其是否存在,或获取其包路径。

3. 元数据检查

使用 mdls 查看 Spotlight 为任何文件存储的丰富元数据。

bash

所有元数据


mdls /path/to/file

特定属性

mdls -name kMDItemKind /path/to/file

常见属性: kMDItemKind、kMDItemContentType、kMDItemAuthors、kMDItemContentCreationDate、kMDItemPixelHeight、kMDItemDurationSeconds。

使用场景: 你需要检查文件属性(创建日期、尺寸、作者)而无需打开文件。

4. 混合搜索(回退)

Spotlight 索引可能不完整(排除的目录、尚未索引的新文件)。附带的脚本 scripts/spotlight_search.sh 提供了混合方法:

  1. 1. 通过 mdfind 尝试 Spotlight 搜索
  2. 如果没有结果,则回退到基于名称匹配的 find
  3. 使用 shell 参数数组而非 eval,因此查询作为数据而非可执行的 shell 文本传递
  4. 支持按类型过滤(pdf、image、application 等)

用法:

bash
./scripts/spotlight_search.sh query
./scripts/spotlight_search.sh -t pdf report
./scripts/spotlight_search.sh -d ~/Documents -l 10 draft

使用场景: 你希望获得最大召回率,或者 Spotlight 对已知文件返回空结果。

参考资料

有关详细的查询语法、运算符参考和高级示例,请参阅:

  • - mdfind 查询参考 – mdfind 语法、属性过滤器、日期比较和实际示例的全面指南。

当你需要构建复杂查询或了解 Spotlight 的功能时,请加载此参考。

工作流程指南

选择合适的工具

场景推荐工具示例
查找包含 budget 的文件mdfind budget内容感知搜索
查找本周修改过的所有 PDF
mdfind kind:pdf AND kMDItemContentModificationDate >= $time.this_week | 元数据过滤搜索 | | 查找 Chrome 应用 | mdfind kMDItemContentType == com.apple.application-bundle && kMDItemFSName == chromecd | 应用程序搜索 | | 仅在 Downloads 文件夹中搜索 | mdfind -onlyin ~/Downloads kind:image | 限定范围搜索 | | 检查文件创建时间 | mdls -name kMDItemContentCreationDate /path/to/file | 元数据检查 | | Spotlight 返回空结果,但我确定文件存在 | ./scripts/spotlight_search.sh filename | 混合回退 |

故障排除

已知文件无结果?

  1. 1. 检查索引状态:mdutil -s /
  2. 确保目录已被索引(Spotlight 会排除某些系统和 Library 文件夹)
  3. 仅在用户明确批准后重新索引,因为这是需要特权的系统级操作:sudo mdutil -E /

查询语法错误?

  • - 将包含空格或特殊字符的查询用单引号括起来。
  • 在 == 后使用 cd 进行大小写和变音符号不敏感匹配:kMDItemFSName == *.pdfcd
  • 使用 AND/OR 和括号组合过滤器。

性能缓慢?

  • - 使用 -limit N 限制结果数量
  • 使用 -onlyin 限制搜索范围

注意事项

  • - Spotlight 索引并非实时;新创建的文件可能需要几分钟才能出现。
  • 某些目录(例如 ~/Library、系统文件夹)可能被排除在索引之外。
  • mdfind 默认搜索所有已索引的卷;使用 -onlyin 进行限制。
  • 混合脚本需要 find(始终存在)和可选的 fd(更快)。

另请参阅

  • - man mdfind
  • man mdls
  • man mdutil
  • Apple 的统一类型标识符参考:https://developer.apple.com/documentation/uniformtypeidentifiers

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 spotlight-search-1776030601 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 spotlight-search-1776030601 技能

通过命令行安装

skillhub install spotlight-search-1776030601

下载

⬇ 下载 spotlight-search v0.1.2(免费)

文件大小: 6.95 KB | 发布时间: 2026-4-13 12:08

v0.1.2 最新 2026-4-13 12:08
Add explicit macOS platform and binary dependency metadata

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部