Skip to content

Instantly share code, notes, and snippets.

@eloo
Created May 13, 2018 18:35
Show Gist options
  • Save eloo/76759af01b407cebb4bfd9ccfc19f8e3 to your computer and use it in GitHub Desktop.
Save eloo/76759af01b407cebb4bfd9ccfc19f8e3 to your computer and use it in GitHub Desktop.
#! /bin/sh
set +o noclobber
# ======================================================
# This script is intended to scan many pages
# over the ADF of a Brother MFC printer
# and save it in one pdf file.
# Tested with MFC-7360N
#
# This script is based on Marcwa19197's ones
# https://github.com/Marcwa19197/brother-skey-scripts/blob/master/scantofile-0.2.4-1.sh
#
# Requirements:
# * graphicsmagick
# ======================================================
# $1 = scanner device
# $2 = friendly name
#
# Settings
#
device=$1 #see with scanimage -L
open_filemanager="true" # open file manager to display created pdf.
outputdir="$HOME/brother-scans"
tmptemplate="brscan-XXXXXX"
output_file="$outputdir/brscan_`date +%F_%H-%M-%S`.pdf"
#scan options
resolution=150 #see scanimage --help (1200 is max on MFC-7360N)
#
# Start Script
#
mkdir -p $outputdir
touch $output_file
tmp_dir=`mktemp -d "$outputdir/$tmptemplate"`
# From Brother, sleeping 1 sec here
if [ "`which usleep`" != '' ]; then
usleep 10000
else
sleep 0.01
fi
# ================================================
# Scan in batch mode
# ================================================
scanimage --device-name "$device" --resolution $resolution --batch="$tmp_dir/tmp-image%02d"
# ==============================================
# Convert all images to a single pdf
# ==============================================
gm convert $tmp_dir/tmp-image* "$output_file"
# ==============================================
# Deleting temporary files
# ==============================================
rm $image
chmod 600 "$output_file"
rm $tmp_dir/*
rmdir $tmp_dir
# ==============================================
# Starting File Manager if requested
# ==============================================
if $open_filemanager = "true";then
if [ "`which nemo`" != '' ];then
nemo $outputdir &
else
if [ "`which nautilus`" != '' ];then
nautilus $outputdir &
else
if [ "`which konqueror`" != '' ];then
konqueror $outputdir &
else
if [ "`which d3lphin`" != '' ];then
d3lphin $outputdir &
fi
fi
fi
fi
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment