daemon like scan2pdf with OCR in Linux

I spend some time rewriting my scanner script.

My script has now these feaures:

  • autocrop
  • OCR via cuneiform
  • daemon like behavior
  • play a sound when script is finished
  • add TODO entry in my orgmode

To get the script running under Ubuntu 12.10 you need some packages:

apt-get install cuneiform sane-utils imagemagick exactimage


Now you need to find the name of you scanner by running

scanimage -L

In my case it is pixma:04A9173A_8447DA

You also need to create a folder to store your pdfs

mkdir $HOME/scans

Now you need to save the script somewhere

nano $HOME/scan2ocr.sh




while :


date=`date +%F-%H-%M-%S`

#scan image

scanimage –device-name $scan_device –format tiff –resolution 150 –mode Gray –button-controlled=yes >/tmp/scan.tiff

# crop image

convert /tmp/scan.tiff -crop `convert /tmp/scan.tiff -virtual-pixel edge -blur 0x15 -fuzz 15% -trim -format ‘%[fx:w]x%[fx:h]+%[fx:page.x]+%[fx:page.y]’ info:` +repage /tmp/scan_crop.tiff

# create one-page pdf
#tiff2pdf -o /home/me/test.pdf -p A4 -F -f /home/me/test_crop.tiff


cuneiform -l ger -f hocr -o /tmp/scan_ocr.hocr /tmp/scan_crop.tiff

# combine *.hocr and *.tiff to pdf file

hocr2pdf -i “/tmp/scan_crop.tiff” -s -o “$path$date.pdf” < “/tmp/scan_ocr.hocr”

# add TODO entry for org-file

echo “* TODO sort [[file:$path$date.pdf]] :scans:” >> $org_file

aplay $sound



and make it executable by


chmod +x $HOME/scan2ocr.sh


Now you can run the script with




The script waits for you to press the scan button and starts the process when pressed. After the image is scanned and processed it will give you a feedback by playing a sound.


You might need to change the path to the sound file you may also don’t want to use the orgmode integration.

using mpd to upload music to your android

I own an android smartphone and I’m a mpd user.

Using mpddroid, sshdroid and ubunturemote app I found a way to upload playlists from my mpd to my android. This way you can use your mpd to organize music on your android

I’m using Ubuntu Remote Control to admin my NAS. Ubuntu Remote Control is actually not limited to Ubuntu. You can use it to control every very Linux machine. So far this is the only app I found which has wake on LAN functionality included. Another aspect of the app I like is the ability to define custom commands and bin icons to them.

You can find Ubuntu Remote Control here

Ubuntu Remote Control on google play store

For my scripts to work you also need sshdroid. sshdroid is app which alows you to connect via ssh on your android. Even it is (like mine) not rooted. You can find sshdroid here:

sshdroid on google play store

For sshdroid to work you need to enable login via ssh-keys.

So ssh on your nas and run:


ssh-copy-id “root@ -p 2222”

where is the IP of your android device. I configured “static” IP for my android via my router as I don’t know any other way to do that on an none rooted android. You can also use your router to find out the local IP of your device.

once you did that you can test the setup via:

ssh root@ -p 2222

if that works you can go on writing some scripts.

This scripts copys the current played track to your android device

# copy current played track on mpd to android device
# simple shortcut to copy files to an android device running sshdroid
# sshdroid needs to be configured with ssh-key authentification
# username is root
file=`mpc -f %file% | head -n 1`
scp -P 2222 “$path” root@
echo “finished transfering files to android device”

And Here is a script to copy a playlist to your android device


while read line
scp -P 2222 “$line” root@
done </var/lib/mpd/playlists/android.m3u