mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 14:49:14 +00:00
packages/easyscan: split script
This commit is contained in:
parent
7d85c4befe
commit
b8df1a2d33
2 changed files with 50 additions and 52 deletions
49
nix/packages/by-name/easyscan/easyscan.sh
Normal file
49
nix/packages/by-name/easyscan/easyscan.sh
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
if [ $# -eq 0 ]; then
|
||||
OUTPUT_FILE=./scan_"$(date)".pdf
|
||||
else
|
||||
OUTPUT_FILE="''${1%.*}.pdf"
|
||||
fi
|
||||
|
||||
tempdir="$(mktemp -d)"
|
||||
|
||||
device=$(scanimage --formatted-device-list="%d (%v %m)" --list-devices |
|
||||
fzf --header "Pick a device:" |
|
||||
cut -d ' ' -f 1)
|
||||
|
||||
do_scan() {
|
||||
filename="$tempdir/$(date).pdf"
|
||||
while ! scanimage --format=pdf --device="$device" --resolution 300 >"$filename"; do
|
||||
:
|
||||
done
|
||||
echo "$filename"
|
||||
}
|
||||
|
||||
do_fix() {
|
||||
read -r filename
|
||||
fixed_name="${filename%.pdf}_fixed.pdf"
|
||||
gs -o "$fixed_name" -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress "$filename"
|
||||
rm "$filename"
|
||||
mv "$fixed_name" "$filename"
|
||||
echo "$filename"
|
||||
}
|
||||
|
||||
while :; do
|
||||
do_scan | do_fix
|
||||
|
||||
IFS= read -r -p "Continue scanning ? [Y/n] " cont
|
||||
case "$cont" in
|
||||
[nN])
|
||||
echo "Exiting..."
|
||||
break
|
||||
;;
|
||||
[yY] | *) ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Multiple files are scanned, join them
|
||||
merged_filename="$tempdir/$(date)_final.pdf"
|
||||
pdfunite "$tempdir"/*.pdf "$merged_filename"
|
||||
echo "$merged_filename" | do_fix
|
||||
|
||||
# Copy scan to current directory
|
||||
cp "$merged_filename" "$OUTPUT_FILE"
|
||||
|
|
@ -15,56 +15,5 @@ writeShellApplication {
|
|||
ghostscript
|
||||
];
|
||||
|
||||
text = ''
|
||||
if [ $# -eq 0 ]; then
|
||||
OUTPUT_FILE=./scan_"$(date)".pdf
|
||||
else
|
||||
OUTPUT_FILE="''${1%.*}.pdf"
|
||||
fi
|
||||
|
||||
tempdir="$(mktemp -d)"
|
||||
|
||||
device=$(scanimage --formatted-device-list="%d (%v %m)" --list-devices |
|
||||
fzf --header "Pick a device:" |
|
||||
cut -d ' ' -f 1)
|
||||
|
||||
do_scan() {
|
||||
filename="$tempdir/$(date).pdf"
|
||||
while ! scanimage --format=pdf --device="$device" --resolution 300 >"$filename"; do
|
||||
:
|
||||
done
|
||||
echo "$filename"
|
||||
}
|
||||
|
||||
do_fix() {
|
||||
read -r filename
|
||||
fixed_name="''${filename%.pdf}_fixed.pdf"
|
||||
gs -o "$fixed_name" -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress "$filename"
|
||||
rm "$filename"
|
||||
mv "$fixed_name" "$filename"
|
||||
echo "$filename"
|
||||
}
|
||||
|
||||
while : ; do
|
||||
do_scan | do_fix
|
||||
|
||||
IFS= read -r -p "Continue scanning ? [Y/n] " cont
|
||||
case "$cont" in
|
||||
[nN])
|
||||
echo "Exiting..."
|
||||
break
|
||||
;;
|
||||
[yY] | *)
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Multiple files are scanned, join them
|
||||
merged_filename="$tempdir/$(date)_final.pdf"
|
||||
pdfunite "$tempdir"/*.pdf "$merged_filename"
|
||||
echo "$merged_filename" | do_fix
|
||||
|
||||
# Copy scan to current directory
|
||||
cp "$merged_filename" "$OUTPUT_FILE"
|
||||
'';
|
||||
text = builtins.readFile ./easyscan.sh;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue