Posted by virantha on Mon 17 March 2014

One-touch scan enabling in Ubuntu Linux for the Fujitsu ScanSnap S1500

Here's how I managed to get Linux to recognise scan button presses on the S1500, and automatically initiate a scan to a pdf file. You first need to download Scanbd and install it. Unfortunately, there doesn't seem to be any apt repository for Scanbd, so I had to download the source and build it. Here's the minimal setup needed to get this built, based on instructions on the web here, followed by updated info that I pieced together on getting this enabled that didin't require xinetd, etc.

1   Building Scanbd

First, as root (sudo su -), install the following packages to allow you to compile Scanbd:

apt-get install build-essential
apt-get install libconfuse-dev libusb-dev libudev-dev libdbus-1-dev dbus libsane-dev

Next, get the source code for Scanbd and build it:

cd /root
mkdir src
cd src
wget -O
make install

2   Configuring Scanbd

Scanbd is now installed into /usr/local/sbin/scanbd, and its configuration files are in /usr/local/etc/scanbd. Follow similar instructions to ArchLinux.

cp -R /etc/sane.d /usr/local/etc/scanbd

Modify /etc/sane.d/dll.conf to only have the net line uncommented, then update the /etc/sane.d/net.conf to have the following

connect_timeout = 3

Now, do the following to startup the daemon that responds to button presses on the S1500

export SANE_CONFIG_DIR=/usr/local/etc/scanbd/sane.d/
/usr/local/sbin/scanbd -df -c scanbd.conf

You can see messages in the syslog /var/log/syslog. After you run the command, it will take about 10 to 15 seconds to detect and start listening to your scanner.

3   Custom scan script

The default script that gets executed when the button is pushed simply logs a message to syslog. (the script is /usr/local/etc/scanbd/test.script). If you look in /usr/local/etc/scanbd/scanbd.conf, you can set test.script to your own shell script. Here's my trigger script that is called scanadf.script:

logger -t "scanbd: $0" "Begin of $SCANBD_ACTION for device $SCANBD_DEVICE"

mydate=$(echo "BLAH" | awk '{ print strftime("%Y%m%d_%H%M%S") }')
scanpdf --dpi=300 -d scan pdf /home/virantha/scans/scan_${mydate}.pdf 2>&1 > /tmp/output.log

logger -t "scanbd: $0" "End   of $SCANBD_ACTION for device $SCANBD_DEVICE"

First, it logs the start of the scan to the syslog, and then it gets the current date using awk/strftime to use for the final pdf filename, and calls my scanpdf python program that handles all the scanning/post processing to pdf. You can find scanpdf documentation online, with source on github, and download on PyPI.

The script as written is slightly suboptimal, in that scanpdf does some processing (removing blank pages, etc) that can take some time, blocking the button response until it's done. A better way would be to spawn a background job to do this instead:

logger -t "scanbd: $0" "Begin of $SCANBD_ACTION for device $SCANBD_DEVICE"

mydate=$(echo "BLAH" | awk '{ print strftime("%Y%m%d_%H%M%S") }')

scanpdf --dpi=300 --tmpdir=/tmp/${mydate} scan
scanpdf --dpi=300 --tmpdir=/tmp/${mydate} pdf ${myfile} &

logger -t "scanbd: $0" "End   of $SCANBD_ACTION for device $SCANBD_DEVICE"

This way, as soon as the paper is out of the scanner, you can load the next job and hit the scan button immediately; the long-running post-processing job is run in the background.

4   Starting Scanbd as a service

Ubuntu uses upstart, so just create a conf file in /etc/init/scanbd like so:

# Scanbd

description "Scanbd service"
author "Virantha Ekanayake"

# When to start the service
start on runlevel [2345]

# When to stop the service
stop on runlevel [016]

# Automatically restart process if crashed

# Essentially lets upstart know the process will detach itself to the background
expect fork

# Specify the process/command to start, e.g.
exec sudo SANE_CONFIG_DIR=/usr/local/etc/scanbd/sane.d/ /usr/local/sbin/scanbd -df -c /usr/local/etc/scanbd/scanbd.conf

Then, run the following command to check this service:

initctl reload-configuration
initctl list | grep scanbd

service scanbd start

Wait about 20 seconds and check:

tail -f /var/log/syslog

ro make sure it started up. Now, after every boot, your scanbd service will be up and running, watching for button presses from your scanner.

© Virantha Ekanayake. Built using Pelican. Modified svbhack theme, based on theme by Carey Metcalfe