1
1
Fork 1
mirror of https://github.com/oddlama/nix-config.git synced 2025-10-10 23:00:39 +02:00

refactor(screenshots): use separate scripts package

This commit is contained in:
oddlama 2023-10-16 00:46:30 +02:00
parent 3e0e03fc31
commit 6e8aae7d8d
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
15 changed files with 216 additions and 109 deletions

View file

@ -0,0 +1,46 @@
{
writeShellApplication,
libnotify,
xclip,
tesseract,
maim,
}:
writeShellApplication {
name = "screenshot-area";
text = ''
set -euo pipefail
umask 077
date=$(date +"%Y-%m-%dT%H:%M:%S%:z")
out="''${XDG_PICTURES_DIR-$HOME/Pictures}/screenshots/$date-selection.png"
mkdir -p "$(dirname "$out")"
${maim}/bin/maim --color=.4,.7,1,0.2 --bordersize=1.0 --nodecorations=1 \
--hidecursor --format=png --quality=10 --noopengl --select "$out"
${xclip}/bin/xclip -selection clipboard -t image/png < "$out"
action=$(${libnotify}/bin/notify-send \
"📷 Screenshot captured" "📋 copied to clipboard" \
--hint="string:wired-tag:screenshot-$date" \
--action=ocr=OCR) \
|| true
if [[ "$action" == "ocr" ]]; then
${libnotify}/bin/notify-send \
"📷 Screenshot captured" " Running OCR ..." \
--hint="string:wired-tag:screenshot-$date" \
|| true
if ${tesseract}/bin/tesseract "$out" - -l eng+deu | ${xclip}/bin/xclip -selection clipboard; then
${libnotify}/bin/notify-send \
"📷 Screenshot captured" "🔠 OCR copied to clipboard" \
--hint="string:wired-tag:screenshot-$date" \
|| true
else
${libnotify}/bin/notify-send \
"📷 Screenshot captured" " Error while running OCR" \
--hint="string:wired-tag:screenshot-$date" \
|| true
fi
fi
'';
}