aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/maimpick
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/maimpick')
-rwxr-xr-x.local/bin/maimpick37
1 files changed, 37 insertions, 0 deletions
diff --git a/.local/bin/maimpick b/.local/bin/maimpick
new file mode 100755
index 0000000..29cf327
--- /dev/null
+++ b/.local/bin/maimpick
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# This is bound to Shift+PrintScreen by default, requires grim (also optionally tesseract and swappy). It lets you
+# choose the kind of screenshot to take, including copying the image or even
+# highlighting an area to copy.
+
+# variables
+output="$(date '+%y%m%d-%H%M-%S').png"
+wclip_cmd="wl-copy -t image/png"
+ocr_cmd="wl-copy"
+
+get_active_window() {
+ hyprctl -j activewindow | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"'
+}
+
+case "$(printf "a selected area\\ncurrent window\\nfull screen\\na selected area (copy)\\ncurrent window (copy)\\nfull screen (copy)\\na selected area (swappy)\\ncurrent window (swappy)\\nfull screen (swappy)\\ncopy selected image to text" | mew -l 10 -i -p "Screenshot which area?")" in
+ "a selected area") geometry=$(slurp) && sleep 0.2 && grim -g "$geometry" pic-selected-"${output}" && notify-send "📸 maimpick" "Screenshot saved as pic-selected-$output." ;;
+ "current window")
+ geometry=$(get_active_window)
+ sleep 0.2
+ grim -g "$geometry" pic-window-"${output}" && notify-send "📸 maimpick" "Screenshot saved as pic-window-$output." ;;
+ "full screen") geometry=$(slurp -o) && sleep 0.2 && grim -g "$geometry" pic-full-"${output}" && notify-send "📸 maimpick" "Screenshot saved as pic-full-$output." ;;
+ "a selected area (copy)") geometry=$(slurp) && sleep 0.2 && grim -g "$geometry" - | ${wclip_cmd} && notify-send "📸 maimpick" "Selected area screenshot copied to clipboard." ;;
+ "current window (copy)")
+ geometry=$(get_active_window)
+ sleep 0.2
+ grim -g "$geometry" - | ${wclip_cmd} && notify-send "📸 maimpick" "Window screenshot copied to clipboard." ;;
+ "full screen (copy)") geometry=$(slurp -o) && sleep 0.2 && grim -g "$geometry" - | ${wclip_cmd} && notify-send "📸 maimpick" "Full screen screenshot copied to clipboard.";;
+ "a selected area (swappy)") geometry=$(slurp) && sleep 0.2 && grim -g "$geometry" - | swappy -f - ;;
+ "current window (swappy)")
+ geometry=$(get_active_window)
+ sleep 0.2
+ grim -g "$geometry" - | swappy -f - ;;
+ "full screen (swappy)") geometry=$(slurp -o) && sleep 0.2 && grim -g "$geometry" - | swappy -f - ;;
+ "copy selected image to text") tmpfile=$(mktemp /tmp/ocr-XXXXXX.png) && slurp | grim -g - - > "$tmpfile" && tesseract "$tmpfile" - -l eng | ${ocr_cmd} && rm "$tmpfile" && notify-send "📸 maimpick" "Detected text copied to clipboard.\n$(wl-paste)" ;;
+ *) notify-send "📸 maimpick" "Wrong option."
+esac