Hyprland 下没找到舒服的 OCR 软件,用脚本代替。
所需软件:Tesseract(OCR 引擎)、Grim(Wayland 截屏)、Slurp(区域选择)、wl-clipboard(剪贴板)
安装:
sudo pacman -S tesseract grim slurp wl-clipboard
脚本内容
#!/bin/bash
# Take a screenshot with Grim and Slurp
grim -g "$(slurp)" /tmp/screenshot.png
# Perform OCR with both Chinese and English language support and copy the result to clipboard
tesseract /tmp/screenshot.png - -l chi_sim+eng | wl-copy
# Optionally, remove the screenshot file
rm /tmp/screenshot.png
赋予执行权限和移动脚本
-
将
ocr_screenshot.sh脚本保存到主目录(如~/ocr_screenshot.sh) -
赋予脚本执行权限:
chmod +x ~/ocr_screenshot.sh -
移动脚本到
/usr/local/bin目录:sudo mv ~/ocr_screenshot.sh /usr/local/bin/
Hyprland 配置
-
打开Hyprland 配置文件,通常位于
~/.config/hypr/hyprland.conf -
添加以下行,将
SUPER + O键组合绑定为执行ocr_screenshot.sh脚本:bind = SUPER, O, exec, ocr_screenshot.sh