Blog Archive

Wednesday, 25 April 2012

How I print remotely using Dropbox

I use Dropbox on my Ubuntu box in my house to print to my home printer when I'm out and about. Here's how I do it: I created a directory ('folder' if you must) called "PRINTBOX" in my Dropbox account.  Next I put this script together :


#!/bin/bash
#printbox
#monitor /home/user/Dropbox/PRINTBOX for new pdf files and print them to the printer then move them to /home/user/printed/
#
PATH=$PATH:/usr/bin:/bin
MONITORDIR=/home/user/Dropbox/PRINTBOX
PRINTEDDIR=/home/user/printed
PRINTER=Black-and-White-Printer
#
ls -1  $MONITORDIR/*.pdf > /dev/null 2>&1
STATUS=$?

if [[ $STATUS -eq 0 ]]
then
  ls -1 $MONITORDIR/*.pdf|while read FILE
  do
    echo $FILE
    echo "lpr -P $PRINTER \"$FILE\""
    lpr -P $PRINTER "$FILE"
    echo "mv \"$FILE\" $PRINTEDDIR/. "
    mv "$FILE" $PRINTEDDIR/.
    echo "\"$FILE\" printed on $PRINTER."
  done
else
  echo "NO FILES"
fi
This then runs in from cron, every 10 minutes.  If it finds a PDF file in the PRINTBOX directory, it, er, prints it!
So basically if I upload a PDF file into that folder using my iPhone and dropbox, it's ready and waiting on the printer when I get home.  Same from my work PC, where I can also run Dropbox.  It even works via the dropbox.com web interface.