-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscreenshot-area.nix
101 lines (87 loc) · 2.42 KB
/
screenshot-area.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{
writeShellApplication,
grimblast,
libnotify,
satty,
tesseract,
wl-clipboard,
}:
writeShellApplication {
name = "screenshot-area";
runtimeInputs = [
grimblast
libnotify
satty
tesseract
wl-clipboard
];
text = ''
umask 077
date=$(date +"%Y-%m-%dT%H:%M:%S%:z")
out_base="''${XDG_PICTURES_DIR-$HOME/Pictures}/screenshots/$date-selection"
out="$out_base.png"
mkdir -p "$(dirname "$out")"
grimblast --freeze save area "$out" || exit 2
wl-copy -t image/png < "$out"
declare -A NOTIFICATION_IDS
function notify_wait_action() {
id="$1"
shift 1
args=("--print-id")
if [[ -v "NOTIFICATION_IDS[$id]" ]]; then
args+=("--replace-id=''${NOTIFICATION_IDS[$id]}")
fi
args+=("$@")
readarray -t __notify_output < <(notify-send "''${args[@]}" || true)
NOTIFICATION_IDS["$id"]="''${__notify_output[0]-}"
echo "''${__notify_output[1]-}"
}
function notify_nowait() {
id="$1"
shift 1
args=("--print-id")
if [[ -v "NOTIFICATION_IDS[$id]" ]]; then
args+=("--replace-id=''${NOTIFICATION_IDS[$id]}")
fi
args+=("$@")
readarray -t __notify_output < <(notify-send "''${args[@]}" || true)
NOTIFICATION_IDS["$id"]="''${__notify_output[0]-}"
unset __notify_output
}
edit_counter=1
title="📷 Screenshot captured"
body="📋 image copied to clipboard"
while true; do
action=$(notify_wait_action main "$title" "$body" \
--action=ocr="🔠 Run OCR" \
--action=edit="✏️ Edit" \
--action=copy="📋 Copy Image")
case "$action" in
ocr)
notify_nowait main "$title" "⏳ Running OCR ..."
if tesseract "$out" - -l eng+deu | wl-copy; then
body="🔠 OCR copied to clipboard"
else
body="❌ Error while running OCR"
fi
;;
edit)
satty --filename "$out" \
--output-filename "$out_base-edit-$edit_counter.png" \
--copy-command wl-copy \
--initial-tool brush \
--save-after-copy \
--fullscreen \
--early-exit
body="🎨 image edited"
edit_counter=$((edit_counter + 1))
;;
copy)
wl-copy -t image/png < "$out"
body="📋 image copied to clipboard"
;;
*) exit 0 ;;
esac
done
'';
}