diff --git a/users/myuser/graphical/i3.nix b/users/myuser/graphical/i3.nix index f470466..7db30d2 100644 --- a/users/myuser/graphical/i3.nix +++ b/users/myuser/graphical/i3.nix @@ -58,10 +58,43 @@ in { out="/tmp/screenshots.$UID/$(date +"%Y-%m-%dT%H:%M:%S%:z")-selection.png" mkdir -p "$(dirname "$out")" ${pkgs.maim}/bin/maim --color=.4,.7,1 --bordersize=1.0 --nodecorations=1 --hidecursor --format=png --quality=10 --noopengl --select "$out" - notification_id=$(${pkgs.libnotify}/bin/notify-send --icon="$out" --print-id --app-name "screenshot" "Screenshot Captured" "Copied to clipboard. Running OCR...") + notification_id=$(${pkgs.libnotify}/bin/notify-send --icon="$out" --print-id --app-name "screenshot-area" "Screenshot Captured" "šŸ“‹ copied to clipboard\nāŒ› Running OCR...") ${pkgs.xclip}/bin/xclip -selection clipboard -t image/png < "$out" - ${pkgs.tesseract}/bin/tesseract "$out" -l eng+deu | ${pkgs.xclip}/bin/xclip -selection primary - ${pkgs.libnotify}/bin/notify-send --icon="$out" --replace-id="$notification_id" --app-name "screenshot" "Screenshot Captured" "Screenshot was copied to clipboard. OCR Content copied to primary." + if ${pkgs.tesseract}/bin/tesseract "$out" - -l eng+deu | ${pkgs.xclip}/bin/xclip -selection primary; then + ${pkgs.libnotify}/bin/notify-send --icon="$out" --replace-id="$notification_id" --app-name "screenshot-area" "Screenshot Captured" "šŸ“‹ copied to clipboard\nāœ… OCR (copied to primary)." + else + ${pkgs.libnotify}/bin/notify-send --icon="$out" --replace-id="$notification_id" --app-name "screenshot-area" "Screenshot Captured" "šŸ“‹ copied to clipboard\nāŒ Error while running OCR." + fi + ''); + "F11" = + "exec --no-startup-id " + # TODO use writeShellApplication for shellcheck + # TODO --icon=some-qr-image + + toString (pkgs.writeShellScript "screenshot-area-scan-qr" '' + set -euo pipefail + + # Create in-memory tmpfile + TMPFILE=$(mktemp) + exec 3<>"$TMPFILE" + rm "$TMPFILE" # still open in-memory as /dev/fd/3 + TMPFILE=/dev/fd/3 + + if ${pkgs.maim}/bin/maim --color=.4,.7,1 --bordersize=1.0 --nodecorations=1 --hidecursor --format=png --quality=10 --noopengl --select \ + | ${pkgs.zbar}/bin/zbarimg --xml - > "$TMPFILE"; then + N=$(${pkgs.yq}/bin/xq -r '.barcodes.source.index.symbol | if type == "array" then length else 1 end' < "$TMPFILE") + # Append codes Copy data separated by --- + DATA=$(${pkgs.yq}/bin/xq -r '.barcodes.source.index.symbol | if type == "array" then .[0].data else .data end' < "$TMPFILE") + for ((i=1;i