Skip to content

Instantly share code, notes, and snippets.

@pmbauer
Last active May 14, 2023 02:43
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmbauer/8fddd5e767ac87c99071819da52cb6c1 to your computer and use it in GitHub Desktop.
Save pmbauer/8fddd5e767ac87c99071819da52cb6c1 to your computer and use it in GitHub Desktop.
OCR Templater Script for Obsidian

OCR Templater Script for Obsidian

Optical Character Recognition (OCR) Templater Script for Obsidian.

Installation

Pre-requisites

Install the Tesseract OCR engine.

Prebuilt Binaries for Linux and Windows are available. On Mac: brew install tesseract.

Create Templater System Command for Tesseract

  1. Open Settings > Templater
  2. Turn on Enable System Commands
  3. Add a User Function named ocr
/usr/local/bin/tesseract "$ocr_input" -

NOTE I reccomend increasing the Templater Timeout to 10s or more as the OCR may take a moment.

Add OCR.md template

Add the OCR.md template to your Templater templates folder.

Usage

  1. Invoke Templater: Create new note from template Pallet command
  2. Choose OCR
  3. Choose an image file in your vault. This may take a few seconds.
creation date tags
<% tp.file.creation_date() %>
OCR

<%* const supportedFileTypes = ["jpeg", "jpg", "png"]; const images = this.app.vault.getFiles().filter((item) => supportedFileTypes.indexOf(item.extension) >= 0); const target = await tp.system.suggester((item) => item.path, images, true); const out = await tp.user.ocr({ocr_input: target.path}); %><%* tR += out %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment