From ce2c9655e0d2ef410443a9cb3b65a9c45ded3b2d Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Tue, 17 Feb 2026 16:51:33 -0500 Subject: [PATCH] feat(scripts): ocr area --- config/hypr/hyprland.conf | 1 - home/home.nix | 12 ++++++------ scripts/ctl | 34 ++++++++++------------------------ 3 files changed, 16 insertions(+), 31 deletions(-) diff --git a/config/hypr/hyprland.conf b/config/hypr/hyprland.conf index 0fe7481..ec7ec6a 100644 --- a/config/hypr/hyprland.conf +++ b/config/hypr/hyprland.conf @@ -133,7 +133,6 @@ bind = , A, exec, hyprctl dispatch submap reset; ctl audio out bind = , C, exec, hyprctl dispatch submap reset; sh -lc 'cliphist list | fuzzel --dmenu --prompt="clip: " | cliphist decode | wl-copy' bind = , I, exec, hyprctl dispatch submap reset; ctl idle bind = , K, exec, hyprctl dispatch submap reset; ctl keyboard next -bind = , O, exec, hyprctl dispatch submap reset; ctl ocr bind = , M, exec, hyprctl dispatch submap reset; ctl media bind = , P, exec, hyprctl dispatch submap reset; ctl power bind = , S, exec, hyprctl dispatch submap reset; ctl screenshot diff --git a/home/home.nix b/home/home.nix index fa75ba2..b18c7c6 100644 --- a/home/home.nix +++ b/home/home.nix @@ -35,12 +35,12 @@ createDirectories = false; download = "${config.home.homeDirectory}/Downloads"; pictures = "${config.home.homeDirectory}/Pictures"; - # desktop = "${config.home.homeDirectory}/Desktop"; - # documents = "${config.home.homeDirectory}/Documents"; - # music = "${config.home.homeDirectory}/Music"; - # publicShare = "${config.home.homeDirectory}/Public"; - # templates = "${config.home.homeDirectory}/Templates"; - # videos = "${config.home.homeDirectory}/Videos"; + desktop = "${config.home.homeDirectory}/Desktop"; + documents = "${config.home.homeDirectory}/Documents"; + music = "${config.home.homeDirectory}/Music"; + publicShare = "${config.home.homeDirectory}/Public"; + templates = "${config.home.homeDirectory}/Templates"; + videos = "${config.home.homeDirectory}/Videos"; }; home.sessionVariables = lib.mkIf hostConfig.isLinux { XDG_DOWNLOAD_DIR = config.xdg.userDirs.download; diff --git a/scripts/ctl b/scripts/ctl index 58d9b12..1876858 100755 --- a/scripts/ctl +++ b/scripts/ctl @@ -22,27 +22,6 @@ screenshot) maim -s "$file" && xclip -selection clipboard -t image/png -i "$file" & fi ;; -ocr) - require tesseract - dir="${XDG_PICTURES_DIR:-$HOME/Pictures}/Screenshots" - mkdir -p "$dir" - file="$dir/$(openssl rand -hex 10)-$(date +'%Y-%m-%d_%H-%M-%S').png" - if [ "${XDG_SESSION_TYPE:-}" = "wayland" ]; then - require grim slurp wl-copy - ( - region="$(slurp)" - [ -n "$region" ] || exit 0 - grim -g "$region" "$file" && - tesseract -l eng "$file" - 2>/dev/null | wl-copy - ) /dev/null 2>&1 & - else - require maim xclip - ( - maim -s "$file" && - tesseract -l eng "$file" - 2>/dev/null | xclip -selection clipboard -in - ) /dev/null 2>&1 & - fi - ;; keyboard) case "$2" in next) @@ -203,7 +182,7 @@ media) exit 0 fi pkill -x fuzzel 2>/dev/null && exit 0 - require fuzzel grim slurp wl-copy wf-recorder hyprctl jq + require fuzzel grim slurp wl-copy wf-recorder hyprctl jq tesseract ss_dir="${XDG_PICTURES_DIR:-$HOME/Pictures}/Screenshots" rec_dir="${XDG_VIDEOS_DIR:-$HOME/Videos}" mkdir -p "$ss_dir" "$rec_dir" @@ -213,7 +192,8 @@ media) rec_desktop=" Record Screen" rec_area=" Record Area" rec_window=" Record Window" - chosen="$(printf '%s\n' "$cap_desktop" "$cap_area" "$cap_window" "$rec_desktop" "$rec_area" "$rec_window" | fuzzel --dmenu --hide-prompt --lines=6 --width=25 --no-icons 2>/dev/null)" + ocr_area=" OCR Area" + chosen="$(printf '%s\n' "$cap_desktop" "$cap_area" "$cap_window" "$rec_desktop" "$rec_area" "$rec_window" "$ocr_area" | fuzzel --dmenu --hide-prompt --lines=7 --width=25 --no-icons 2>/dev/null)" case "$chosen" in "$cap_desktop") file="$ss_dir/$(date +'%Y-%m-%d_%H-%M-%S').png" @@ -247,6 +227,12 @@ media) notify-send -a ctl -t 2500 "Recording started" wf-recorder -g "$geom" -f "$file" & ;; + "$ocr_area") + file="$ss_dir/$(date +'%Y-%m-%d_%H-%M-%S').png" + region="$(slurp)" || exit 0 + [ -n "$region" ] || exit 0 + grim -g "$region" "$file" && tesseract -l eng "$file" - 2>/dev/null | wl-copy + ;; esac ;; wallpaper) @@ -424,7 +410,7 @@ idle) fi ;; *) - echo "Usage: ctl {screenshot|ocr|keyboard|audio|wifi|brightness|volume|media|wallpaper|power|idle}" >&2 + echo "Usage: ctl {screenshot|keyboard|audio|wifi|brightness|volume|media|wallpaper|power|idle}" >&2 exit 1 ;; esac