os/pkgs/scan2paperless.nix

30 lines
790 B
Nix

self:
with self; ''
export PATH=${lib.makeBinPath [pkgs.coreutils pkgs.sane-frontends pkgs.sane-backends pkgs.ghostscript pkgs.imagemagick]}
NAME=$([ "$1" == "" ] && date -Iseconds || echo "$1")
TMPDIR=$(mktemp -d)
echo "Using ''${NAME}.pdf as filename"
RESPONSE=""
while [ -z "$RESPONSE" ];
do
DATETIME=$(date -Iseconds)
echo "Starting scan $DATETIME"
scanimage \
-d "''${SCANNER_DEFAULT_DEVICE}" \
--format=jpeg \
--resolution 300 \
--progress \
-o "''${TMPDIR}/''${DATETIME}.jpg"
read -p "Press ENTER to scan another page, or any other key to generate the final PDF: " RESPONSE < /dev/tty
done
${python39Packages.img2pdf}/bin/img2pdf --output "''${SCANNER_OUTPUT_DIR}/''${NAME}.pdf" ''${TMPDIR}/*
rm -rf TMPDIR
''