random-scripts/wayland-screenshot.sh

38 lines
1.0 KiB
Bash
Raw Normal View History

2023-09-14 11:41:52 -07:00
#!/usr/bin/zsh
local resp="$(fuzzel --index -d <<'EOF'
Whole screen
Current window
Selected area
2023-10-30 01:01:04 -07:00
Copy text with OCR
2023-09-14 11:41:52 -07:00
EOF
)"
local outfile="$(date +'screenshot-%F--%H-%M-%S.png')"
case "${resp}" in
0)
grim "${outfile}"
;;
1)
local active_window="$(hyprctl -j activewindow)"
[[ activewindow == '{}' ]] ||
jq -r --null-input --argjson 'window' "${active_window}" \
'$window | "\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"' |
grim -g - "${outfile}"
;;
2)
local area="$(slurp 2>&1)"
[[ "${area}" == 'selection cancelled' ]] ||
grim -g "${area}" "${outfile}"
;;
2023-10-30 01:01:04 -07:00
3)
local area="$(slurp 2>&1)"
if [[ "${area}" != 'selection cancelled' ]]; then
local text="$(grim -g "${area}" -t png /dev/fd/1 |
tesseract stdin stdout -l eng 2>/dev/null)"
wl-copy "${text}"
notify-send -t 5000 "Coppied Text" "Coppied ${#text} characters"
fi
2023-09-14 11:41:52 -07:00
esac