CommunityImagegithub.com

GreenWich-art/agent-skills

Local OCR using the macOS Vision framework. Supports triggers such as OCR, extract text from images, screenshots, photos, scanned PDFs. Local-first and offline; prefer it over cloud OCR whenever data is sensitive or the machine is offline.

What is agent-skills?

This skill provides offline, local OCR for macOS by leveraging the system's built-in Vision framework via the `macocr` command. It processes images (PNG, JPG, HEIC, TIFF) and scanned PDFs entirely on-device, ensuring data never leaves the machine. The skill includes environment checks, installation guidance, and a standard workflow for converting user-provided images or PDFs to text. It supports advanced parameters such as language selection (Chinese/English), region-based OCR (`--rect`), upscaling for blurry images (`--upscale`), and orientation correction (`--orientation`). It also offers troubleshooting steps for low accuracy, including image preprocessing with PIL and multi-version voting for tables. The skill is designed for use with AI agents like Claude Code, Cursor, or Codex, and is ideal for sensitive data scenarios. It requires macOS 13+ and Xcode Command Line Tools or a precompiled binary for Apple Silicon.

Works with~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/GreenWich-art/agent-skills/tree/HEAD/skills/macos-vision-ocr

Installed? Explore more Image skills: steipete/songsee, affaan-m/frontend-design, mattpocock/improve-codebase-architecture · View all 6 →

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

macOS Vision Local OCR

This skill guides you in converting user-provided images/PDFs to text: using macOS's built-in Vision engine (macocr command) for local recognition, with no data uploaded.

Environment Check (Mandatory)

Before calling any OCR command, run the following check. If any condition is not met, stop and respond accordingly:

[ "$(uname -s)" = "Darwin" ] && echo OK-macOS
command -v macocr || ls "$HOME/.local/bin/macocr"
  • uname is not Darwin: This tool only supports macOS. Do not attempt to install or compile; directly inform the user that this Skill is only available on macOS and suggest using other OCR solutions.
  • macocr not found: Guide the user to run ./install.sh in this package directory (compilation requires Xcode Command Line Tools; on Apple Silicon without a compilation environment, it automatically falls back to the precompiled binary). After installation, run sh scripts/selftest.sh for an end-to-end self-test. Proceed only after it passes.

Once installation and self-test are complete, there is no need to repeat them for each session.

Standard Task Execution Flow

Follow these steps to handle the user's OCR request; do not skip steps:

  1. Confirm input type. If the user provides an image (png/jpg/jpeg/heic/tiff), proceed directly to step 3. If it is a scanned PDF (no text layer), first go to step 2 to convert to images.

  2. PDF to image conversion (only needed for scanned PDFs). Use the system's sips tool for rendering, starting at 144dpi:

    sips -s format png -s dpiHeight 144 -s dpiWidth 144 input.pdf --out /tmp/p1.png
    

    Note: sips handles only single pages; for multi-page PDFs, you must specify each page separately, or use pymupdf with a 4x matrix for rendering (significantly better for small-font course materials, see "How to Use Scanned PDFs").

  3. Run recognition. The default command covers most scenarios:

    macocr <image path>            # Multiple images can be listed sequentially; output separated by ===
    

    Add parameters as appropriate per scenario (see parameter table below). The result is plain text, already arranged in visual line order.

  4. Deliver results. Present the recognized text directly to the user; for table/number-dense results, remind the user to double-check critical numbers (see "Special Considerations for Table Data").

Parameter Quick Reference

ParameterPurpose
--fastDisable language correction. Recommended for tables and numbers to prevent numbers from being "corrected" to odd values
--lang zh-Hans+en-USDefault for mixed Chinese/English. Set to en-US for pure English for speed; use zh-Hant for Traditional Chinese
--rect x,y,w,hRecognize only a rectangular region (origin top-left, pixels). Use when extracting only a specific table from a large image
--upscale NFor blurry small images (e.g., forwarded images <1000px wide) or old scans: first Lanczos upscale by N (1.0–4.0). Only try 2 → 3 incrementally when normal mode accuracy is poor; blindly upscaling sharp large images can cause stroke merging
--orientation up|left|right|180Manually correct camera rotation/flip. Vision does not auto-rotate based on EXIF; side-shot images must use this
--list-langsList supported recognition languages on the machine (for installation self-test; output should include zh-Hans)

Troubleshooting Low Accuracy (in Order of Increasing Cost)

Try these from lowest to highest cost; do not jump to complex solutions immediately:

  1. Get the original image: Forwarded chat images have very low recognition rate; first ask the user to provide the original file.
  2. --rect to isolate the target region, reducing noise.
  3. --upscale 2 (for blurry small images).
  4. --fast (for table/number scenarios).
  5. Image preprocessing (crop + grayscale + auto-contrast + sharpen + binarization), example below:
from PIL import Image, ImageOps, ImageEnhance
im = Image.open("src.JPG")
im.crop((x0, y0, x1, y1)).resize((w*2, h*2), Image.LANCZOS)   # crop + upscale
ImageOps.autocontrast(im.convert("L"))                         # grayscale + auto contrast
ImageEnhance.Sharpness(im).enhance(2.0)                        # sharpen
im.convert("L").point(lambda p: 255 if p > 128 else 0)         # binarize

Multi-version voting: Run 2–3 preprocessing variants on the same table, take the consensus parts, and separately review any inconsistent numbers. Cross-validation: If sums of whole rows/columns match, the result is likely reliable; if not, a number is wrong.

Why Does the Photos App's Live Text Seem More Accurate Than the Bare API?

It uses the same Vision engine. The difference comes from pre- and post-processing, not the model itself:

  1. Orientation: "Photos" auto-rotates based on EXIF before recognition; the bare API defaults to .up → use --orientation to compensate.
  2. Resolution: "Photos" uses the original full-resolution image; images in workflows are often compressed previews → always prefer the original file first.
  3. Implicit downsampling: NSImage renders at "points"; @2x/@3x screenshots and some HEIC images lose half the pixels → This tool iterates over representations to get the largest bitmap.
  4. Vertical text: Live Text handles vertical text; the bare API breaks it into fragmented lines → This tool auto-detects and applies confidence arbitration.
  5. Interaction advantage (cannot be fully replicated): Live Text allows point selection, making errors feel "fewer"; CLI outputs the entire text at once, making every mistake visible.

Conclusion: Same engine, pipeline determines the ceiling.

Special Considerations for Table Data

OCR is most error-prone on tables: decimal points may be swallowed (. → ,), adjacent columns might merge into one string, and rows can be mixed up. Critical numbers must be double-checked: if a PDF original exists, extract its text layer for comparison; if only a photo is available, rely on multi-version voting plus row/column logic validation.

When Not to Use This Tool

ScenarioMore Suitable Choice
The AI model itself can read imagesLet it see the image directly; no need for OCR
Complex layout reconstruction needed (multi-column, formulas, table border structure)Layout-aware parsing services like MinerU (data goes to cloud)
Batch converting entire scanned PDFs to text and cloud is acceptableCloud OCR service's batch interface

Rule: Local first, no data leakage; only go to cloud when higher accuracy is essential, and only after confirming data can be sent externally.

Verification & Troubleshooting

  • Post-installation self-test: sh scripts/selftest.sh (end-to-end test using package's test image; outputs PASS/FAIL).
  • Language list does not include zh-Hans: System language data is incomplete, very rare; check if macOS version ≥ 13.
  • Empty or completely wrong output: First confirm the image is readable (sips -g pixelWidth -g pixelHeight image), then try the "Troubleshooting Low Accuracy" steps incrementally.

System Requirements

  • macOS 13+ (automaticallyDetectsLanguage requires 13.0)
  • Xcode Command Line Tools for compilation (xcode-select --install); or use the precompiled Apple Silicon binary (scripts/macocr-arm64, ad-hoc signed).

Package File Reference

FilePurposeWhen Needed
install.shInstall macocr (compile first, precompiled fallback)When environment check shows macocr is missing
scripts/selftest.sh + scripts/selftest.pngEnd-to-end self-test (script + built-in test image)Verification after installation; run this first when troubleshooting recognition anomalies to confirm the tool itself works
scripts/vision_ocr.swiftSource code (~200 lines, auditable)When needing to compile manually or audit
scripts/macocr-arm64Precompiled Apple Silicon binaryFor Apple Silicon machines without swiftc; automatically used by install.sh

Individual skills in this repo

This repo contains 4 individual skills — each has its own dedicated page.

GreenWich-art/agent-skills

桌面 GUI 操作的统一编排入口。当用户要求操作一个只有图形界面的应用(改设置、点按钮、填表单、操作无 CLI/连接器的软件)时使用此 skill。提供四级能力:①路由决策——判断任务该走连接器、浏览器控制、Office 技能、命令行还是 computer use 桌面接管;②授权引导——检测并引导用户完成 macOS 辅助功能/屏幕录制权限授权,处理授权不生效等常见坑;③任务派发与验证——按目标/边界/失败处理三段式描述派发 GUI 任务,并以最终截图为准确认结果;④AX 兜底层——内置 axctl 工具做元素级无障碍读写(AXPress 语义点击,不碰鼠标不抢焦点),适用于 computer use 不可用或轻量场景。台前调度全场景实测(macOS 15 + 27.0.1 复检)。触发词:操控电脑、操作某个软件、点某个按钮、GUI 操作、电脑设置。

GreenWich-art/agent-skills

按学术论文规范(小三黑体一级标题/四号黑体二级/小四正文宋体1.5倍行距/三线表/中西文混排Times New Roman/统计量斜体) 批量重整 Markdown 或已有 docx 的格式。用户说"按学术格式排版""三线表""小三号黑体标题""1.5倍行距" "数字英文用Times New Roman""P值斜体"时使用。基于 python-docx 直接生成 docx,不走逐段插入。 不适用:高校课程论文/作业的字体字号约定(标准不同);党政机关公文国标 GB/T 9704 (又是另一套标准)。三套标准不可混用。

GreenWich-art/agent-skills

参考文献的 GB/T 7714-2015 著录规范化,以及 URL / DOI / PMID / PMC 链接的 可访问性批量核验与"假失效"识别。 触发场景: - 论文 / 综述 / 作业要交,需要核对参考文献格式 - "帮我按国标改一下参考文献" - 要交付一份文献清单,需要确认链接没死 - 已经有一堆 links,要批量验证哪些还能打开 含一个可复用脚本 `scripts/check_refs.py`,能自动判别 URL / DOI / PMID / PMC 并并发核验,且能区分「真死」与「被反爬」——后者不该判为失效。 不适用:从零生成一份带引文的正文(那是写作任务); Zotero 样式定制(见正文第六节,按需手工改 CSL)。

GreenWich-art/agent-skills

Download open-access biomedical article PDFs from PMC with offline Proof-of-Work solving. Triggers: 下载文献PDF, PMC PDF, 403/404 on PDF link, Preparing to download, reCAPTCHA page, OA full text, supplementary files, download paper PDF.

Related Skills