Skip to content

Commit a7351cd

Browse files
Merge pull request #1332 from anshifmonz/feat/text-extractor-from-screen
feat: add screen text extractor script
2 parents a1a2e08 + 3bfe8be commit a7351cd

File tree

7 files changed

+48
-3
lines changed

7 files changed

+48
-3
lines changed

docs/getting-started/dependencies.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ gum
1212
rsync
1313
git
1414
figlet
15-
xdg-user-dirs
15+
xdg-user-dirs
1616
hyprland
1717
hyprpaper
1818
hyprlock
@@ -42,6 +42,9 @@ htop
4242
blueman
4343
grim
4444
slurp
45+
tesseract
46+
tesseract-data-eng (or tesseract-langpack-eng on Fedora, tesseract-ocr-traineddata-eng on openSUSE)
47+
wl-clipboard
4548
cliphist
4649
nwg-look
4750
qt6ct

dotfiles/.config/hypr/conf/keybindings/default.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ bind = $mainMod SHIFT, A, exec, $HYPRSCRIPTS/toggle-animations.sh
5353
bind = $mainMod, PRINT, exec, $HYPRSCRIPTS/screenshot.sh # Take a screenshot
5454
bind = $mainMod ALT, F, exec, $HYPRSCRIPTS/screenshot.sh --instant # Take an instant full-screen screenshot
5555
bind = $mainMod ALT, S, exec, $HYPRSCRIPTS/screenshot.sh --instant-area # Take an instant area screenshot
56+
bind = $mainMod ALT, A, exec, $HYPRSCRIPTS/text-extractor.sh # Extract text from an area
5657
bind = $mainMod CTRL, Q, exec, ~/.config/ml4w/scripts/wlogout.sh # Start wlogout
5758
bind = $mainMod SHIFT, W, exec, ~/.config/hypr/scripts/waypaper.sh --random # Change the wallpaper
5859
bind = $mainMod CTRL, W, exec, ~/.config/hypr/scripts/waypaper.sh # Open wallpaper selector
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeuo pipefail
4+
5+
PICKER_PID=""
6+
SLURP_TIMEOUT=10
7+
DEPS=(grim slurp magick tesseract wl-copy timeout)
8+
9+
die() { echo "Error: $*" >&2; exit 1; }
10+
safe_kill() { [[ -n "${1:-}" ]] && kill "$1" 2>/dev/null || true; }
11+
cleanup() { safe_kill "$PICKER_PID"; }
12+
trap cleanup EXIT INT TERM
13+
14+
check_deps() {
15+
local missing_dependencies=()
16+
for dep in "${DEPS[@]}"; do command -v "$dep" >/dev/null 2>&1 || missing_dependencies+=("$dep"); done
17+
if (( ${#missing_dependencies[@]} > 0 )); then
18+
die "Missing dependencies: ${missing_dependencies[*]}"
19+
fi
20+
}
21+
22+
check_deps
23+
24+
hyprpicker -r -z &
25+
PICKER_PID=$!
26+
sleep 0.1 || true
27+
28+
REGION=$(timeout "$SLURP_TIMEOUT" slurp -b "#00000080" -c "#888888ff" -w 1) || die "No region selected (timeout or cancelled)"
29+
[[ -z "$REGION" ]] && die "No region selected"
30+
cleanup
31+
32+
grim -g "$REGION" - \
33+
| magick - -colorspace Gray -normalize -contrast-stretch 2% -sharpen 0x1.0 -resize 200% png:- \
34+
| tesseract - stdout -l eng --psm 6 \
35+
| wl-copy \
36+
|| die "Failed to capture or process text"

setup/pkgs.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ apps=(
3737
)
3838

3939
tools=(
40-
"xdg-user-dirs"
41-
"xdg-desktop-portal-gtk"
40+
"xdg-user-dirs"
41+
"xdg-desktop-portal-gtk"
4242
"figlet"
4343
"fastfetch"
4444
"htop"
@@ -52,5 +52,7 @@ tools=(
5252
"gvfs"
5353
"grim"
5454
"breeze"
55+
"tesseract"
56+
"wl-clipboard"
5557
"btop"
5658
)

setup/setup-arch.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ packages=(
4646
# Tools
4747
"eza"
4848
"python-pywalfox"
49+
"tesseract-data-eng"
4950
# Fonts
5051
"otf-font-awesome"
5152
"ttf-firacode-nerd"

setup/setup-fedora.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ packages=(
3333
"fuse"
3434
"ImageMagick"
3535
"NetworkManager-tui"
36+
"tesseract-langpack-eng"
3637
# Apps
3738
"waypaper"
3839
"swww"

setup/setup-opensuse.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ packages=(
3131
"ImageMagick"
3232
"NetworkManager-connection-editor"
3333
"NetworkManager-tui"
34+
"tesseract-ocr-traineddata-eng"
3435
# Apps
3536
"SwayNotificationCenter"
3637
# Fonts

0 commit comments

Comments
 (0)