From 75eec08758599774ec024601184c00bb89b7971a Mon Sep 17 00:00:00 2001 From: K T Prajwal Prathiksh Date: Sun, 3 May 2026 08:25:33 -0500 Subject: [PATCH] Add screenshot OCR functionality with Minimal Dependencies (#1918) * Add script to capture screenshot, perform OCR, and copy text to clipboard * Add binding for screenshot-ocr * Update OCR binding description * Add tesseract OCR and language data installation * Update bindings to current dev * Refactor screenshot capture method to use wayfreeze and slurp for region selection * Refactor OCR text extraction to simplify error handling * Bring up to date --------- Co-authored-by: David Heinemeier Hansson --- bin/omarchy-capture-text-extraction | 26 ++++++++++++++++++++++++++ bin/omarchy-menu | 3 ++- default/hypr/bindings/utilities.conf | 1 + install/omarchy-base.packages | 2 ++ migrations/1758734243.sh | 3 +++ 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 bin/omarchy-capture-text-extraction create mode 100644 migrations/1758734243.sh diff --git a/bin/omarchy-capture-text-extraction b/bin/omarchy-capture-text-extraction new file mode 100755 index 00000000..cb0c62b5 --- /dev/null +++ b/bin/omarchy-capture-text-extraction @@ -0,0 +1,26 @@ +#!/bin/bash + +# omarchy:summary=Extract text from a screenshot region with OCR +# omarchy:group=capture +# omarchy:examples=omarchy capture ocr + +# Keep hyprpicker alive until after grim captures so the screenshot sees the +# frozen overlay rather than live content shifting during teardown. +cleanup_freeze() { + [[ -n $PID ]] && kill $PID 2>/dev/null +} +trap cleanup_freeze EXIT + +hyprpicker -r -z >/dev/null 2>&1 & +PID=$! +sleep .1 +SELECTION=$(slurp 2>/dev/null) + +[[ -z $SELECTION ]] && exit 0 + +TEXT=$(grim -g "$SELECTION" - | tesseract stdin stdout --oem 1 --psm 6 -l eng --dpi 300 -c preserve_interword_spaces=1 2>/dev/null) || exit 1 + +[[ -z $TEXT ]] && exit 1 + +printf "%s" "$TEXT" | wl-copy +notify-send "󰴑 Copied text from selection to clipboard" diff --git a/bin/omarchy-menu b/bin/omarchy-menu index b837b3f4..e92585cf 100755 --- a/bin/omarchy-menu +++ b/bin/omarchy-menu @@ -103,9 +103,10 @@ show_trigger_menu() { } show_capture_menu() { - case $(menu "Capture" " Screenshot\n Screenrecord\n󰃉 Color") in + case $(menu "Capture" " Screenshot\n Screenrecord\n󰴑 Text Extraction\n󰃉 Color") in *Screenshot*) omarchy-capture-screenshot ;; *Screenrecord*) show_screenrecord_menu ;; + *Text*) omarchy-capture-text-extraction ;; *Color*) pkill hyprpicker || hyprpicker -a ;; *) back_to show_trigger_menu ;; esac diff --git a/default/hypr/bindings/utilities.conf b/default/hypr/bindings/utilities.conf index bc912f0e..b2cf33ce 100644 --- a/default/hypr/bindings/utilities.conf +++ b/default/hypr/bindings/utilities.conf @@ -38,6 +38,7 @@ bindl = , switch:off:Lid Switch, exec, omarchy-hyprland-monitor-internal on bindd = , PRINT, Screenshot, exec, omarchy-capture-screenshot bindd = ALT, PRINT, Screenrecording, exec, omarchy-menu screenrecord bindd = SUPER, PRINT, Color picker, exec, pkill hyprpicker || hyprpicker -a +bindd = SUPER CTRL, PRINT, Extract text (OCR) from screenshot, exec, omarchy-capture-text-extraction # File sharing bindd = SUPER CTRL, S, Share, exec, omarchy-menu share diff --git a/install/omarchy-base.packages b/install/omarchy-base.packages index 4d609b8e..acdddc47 100644 --- a/install/omarchy-base.packages +++ b/install/omarchy-base.packages @@ -120,6 +120,8 @@ sushi swaybg swayosd system-config-printer +tesseract +tesseract-data-eng tldr tree-sitter-cli tmux diff --git a/migrations/1758734243.sh b/migrations/1758734243.sh new file mode 100644 index 00000000..a264567e --- /dev/null +++ b/migrations/1758734243.sh @@ -0,0 +1,3 @@ +echo "Install tesseract OCR and language data files" + +omarchy-pkg-add tesseract tesseract-data-eng \ No newline at end of file