From mactools
通过 macOS Spotlight 全局检索本地文件并读取内容,作为私有知识库使用。支持 Word、Excel、PPT、PDF、Markdown 等格式的文本提取。当用户要求搜索本地文件、查找文档、检索电脑上的资料、查看本地文件内容时使用。Use when the user needs to search local files, find documents, or retrieve content from the local disk. Supports Word, Excel, PPT, PDF, Markdown formats. Keywords: 搜索文件, 找文件, 本地搜索, Spotlight, 知识库, 电脑上, 磁盘上, 硬盘上, 本地文档.
npx claudepluginhub n0rvyn/indie-toolkit --plugin mactoolsThis skill is limited to using the following tools:
通过 macOS Spotlight 索引全局检索本地文件,提取文档内容,搜索 + 阅读 + 理解。
Compares coding agents like Claude Code and Aider on custom YAML-defined codebase tasks using git worktrees, measuring pass rate, cost, time, and consistency.
Designs and optimizes AI agent action spaces, tool definitions, observation formats, error recovery, and context for higher task completion rates.
Designs, implements, and audits WCAG 2.2 AA accessible UIs for Web (ARIA/HTML5), iOS (SwiftUI traits), and Android (Compose semantics). Audits code for compliance gaps.
通过 macOS Spotlight 索引全局检索本地文件,提取文档内容,搜索 + 阅读 + 理解。
BASE="${CLAUDE_PLUGIN_ROOT:-${CODEX_HOME:-$HOME/.codex}}"
SKILLS_ROOT="$BASE/skills"
[ -d "$SKILLS_ROOT/spotlight/scripts" ] || SKILLS_ROOT="$BASE/indie-toolkit/mactools/skills"
${SKILLS_ROOT}/spotlight/scripts/spotlight.sh
python3 ${SKILLS_ROOT}/spotlight/scripts/extract_text.py <file_path> [--max-chars N]
支持提取的格式:
| 格式 | 提取方式 | 说明 |
|---|---|---|
| doc/docx/rtf/odt/pages | textutil | macOS 原生,提取质量高 |
| xlsx | openpyxl | 按 Sheet 输出,保留表格结构 |
| xls | textutil/strings | 旧格式,尽力提取 |
| pptx | zipfile XML | 按 Slide 输出文本 |
| ppt | textutil/strings | 旧格式,尽力提取 |
| pdftotext | 文字型 PDF 效果好;扫描件无法提取 | |
| txt/md/csv/json/yaml/code | 直接读取 | 支持 UTF-8/GBK 编码 |
--max-chars 默认 50000,可根据需要调整。
${SKILLS_ROOT}/spotlight/scripts/spotlight.sh search "关键词"
${SKILLS_ROOT}/spotlight/scripts/spotlight.sh search -d ~/Documents "关键词"
${SKILLS_ROOT}/spotlight/scripts/spotlight.sh search -t md "关键词"
${SKILLS_ROOT}/spotlight/scripts/spotlight.sh search -t pdf -d ~/Downloads "机器学习"
${SKILLS_ROOT}/spotlight/scripts/spotlight.sh search -name "README"
${SKILLS_ROOT}/spotlight/scripts/spotlight.sh search -name -d ~/Code -t swift "ViewModel"
${SKILLS_ROOT}/spotlight/scripts/spotlight.sh recent 7
${SKILLS_ROOT}/spotlight/scripts/spotlight.sh recent -d ~/Code -t md 3
${SKILLS_ROOT}/spotlight/scripts/spotlight.sh meta /path/to/file
| 参数 | 说明 | 示例 |
|---|---|---|
-d <dir> | 限定搜索目录 | -d ~/Documents |
-t <type> | 文件类型过滤 | -t pdf |
-n <count> | 最大结果数(默认 20) | -n 10 |
-name | 只匹配文件名 | -name |
| 短名 | 文件类型 |
|---|---|
md | Markdown |
pdf | |
swift | Swift 源码 |
py | Python 脚本 |
txt | 纯文本 |
doc/docx | Word 文档 |
xls/xlsx | Excel 表格 |
ppt/pptx | PowerPoint |
pages | Apple Pages |
keynote | Apple Keynote |
numbers | Apple Numbers |
html | HTML |
json | JSON |
yaml | YAML |
csv | CSV |
code | 所有源代码(广义匹配) |
image | 所有图片 |
audio | 所有音频 |
video | 所有视频 |
从用户问题中判断:
用 Bash 调用 spotlight.sh,根据意图组合参数。
如果结果太多,缩小范围(加 -d、-t、减小 -n)。
如果结果太少,扩大范围(去掉 -t、去掉 -d、换关键词)。
从搜索结果中选择最相关的文件,用 extract_text.py 提取内容。
选择标准:
提取命令:
# 提取单个文件
python3 ${SKILLS_ROOT}/spotlight/scripts/extract_text.py "/path/to/file.xlsx"
# 限制提取长度(大文件时使用)
python3 ${SKILLS_ROOT}/spotlight/scripts/extract_text.py "/path/to/large.docx" --max-chars 20000
对于纯文本格式(txt/md/code 等),也可以直接用 Read 工具读取。extract_text.py 的优势在于处理二进制文档格式(Office/PDF)。
如果需要从多个文件中提取信息,可以并行调用多个 extract_text.py 命令。
基于提取的文件内容回答用户问题。回答时注明信息来源:
根据本地文件 [文件名](路径:/path/to/file):
[整合后的回答]
如果提取结果显示 [Info] PDF contains no extractable text,说明是扫描件/图片型 PDF,告知用户该文件无法提取文字。
spotlight.sh 覆盖常见场景。遇到复杂查询时,可以直接使用 mdfind:
# 按作者搜索
mdfind "kMDItemAuthors == '*张三*'"
# 按文件大小(大于 10MB)
mdfind "kMDItemFSSize > 10485760"
# 组合条件:最近 30 天修改的 PDF 且包含 "AI"
mdfind "kMDItemContentModificationDate >= \$time.today(-30) && kMDItemContentType == 'com.adobe.pdf' && kMDItemTextContent == '*AI*'c"
# 搜索 Xcode 项目文件
mdfind "kMDItemContentType == 'com.apple.xcode.project'"
--max-chars 限制提取长度,避免输出过长