我希望自动让我的打印机按照设定的时间间隔扫描文档,这样我就可以换出并扫描我的文档,而无需每次都单击计算机上的按钮。我还需要能够将文档保存为特定的图像格式和质量。最好,我希望能够从 bash 脚本执行此操作,以便它可以在任何发行版上运行。我该怎么做呢?
答案1
我专门为此目的创建了一个脚本。https://github.com/aaronfranke/Linux-tools/blob/master/all-distros/autoscan.sh
在运行之前编辑顶部的变量。您必须指定打印机的地址,可以通过运行找到该地址scanimage -L
。您还可以指定时间间隔、格式和质量 (PPI)。该脚本会将扫描的图像保存到随机的 6 个字符的文件名中。
注意:此脚本需要安装scanimage
和命令。mogrify
#!/bin/bash
# autoscan.sh - A script for automatically scanning from a printer/scanner and saving to a random file.
# Must be set to your printer's address. Use `scanimage -L` to get a list of printers.
PRINTER="hpaio:/net/OfficeJet_4650_series?ip=192.168.0.100"
# Optional variables, feel free to adjust.
TIME=30 # TIME (in seconds), should be at least 10.
FORMAT=jpg # FORMAT must be understood by mogrify. Ex: jpg, png, tiff, bmp.
QUALITY=200 # QUALITY must be supported by your printer. Common ones are 300, 200, 150, and 75.
if [ ! -f /usr/bin/scanimage ]; then
echo "This script requires the \`scanimage\` command, which was not found. Exiting. "
exit 1
fi
if [ ! -f /usr/bin/mogrify ]; then
echo "This script requires the \`mogrify\` command from the \`imagemagick\` package, which was not found. Exiting. "
exit 2
fi
echo " "
echo "Computer will start automatically scanning in a few seconds... "
SLTIME=$(($TIME-5))
sleep 5
while true; do
FILENAME=$(mktemp -u XXXXXX)
echo " "
echo "Scanning and saving to $FILENAME.$FORMAT... "
scanimage -d $PRINTER --mode Color --resolution $QUALITY --format tiff > $FILENAME.tiff 2>/dev/null
mogrify -format $FORMAT $FILENAME.tiff
rm $FILENAME.tiff
echo " "
echo "Done scanning $FILENAME.$FORMAT, waiting $TIME seconds for next scan... "
sleep $SLTIME
echo " "
echo "5... "
sleep 1
echo "4... "
sleep 1
echo "3... "
sleep 1
echo "2... "
sleep 1
echo "1... "
sleep 1
done