The idea is that you create a shell script to monitor a local Dropbox folder. As soon as a new file is added to that folder from a remote computer (or mobile phone), the script will send the file to the attached printer. Once the the printing job is completed, the file is removed from the incoming queue.
You only have to setup a cron job against this script such that it runs after every ‘n’ seconds (or minutes).
#!/bin/bash export PrintQueue="/root/Dropbox/PrintQueue"; IFS=$'\n' for PrintFile in $(/bin/ls -1 ${PrintQueue}) do lpr -r ${PrintQueue}/${PrintFile}; done
To initiate a print job, simply add some files to the PrintQueue Folder in Dropbox from either a remote computer or upload them via your mobile phone. Within seconds, the script will start printing the files to your local printer.
If you have multiple printers attached to Linux computer, use the – p parameter to specify the printer name.
Also, if you are on Ubuntu, you may use “sudo apt-get install gnome-schedule” (Gnome Schedule) to setup a scheduled task for the script with recurrence set to “every minute.”
DROPBOX PRINTING WITH LINUX DECODED
Here’s an annotated version of the script, courtesy Kurt again, that will help you easily understand how the script works:
#!/bin/bash — Specific bash directly since its feature set and behaviors are consistent everywhere
export PrintQueue — It’s necessary to ‘export’ in order for the environment variable to show up in the later $() subshell
IFS=$’\n’ — By default, spaces will wreak havoc with the ‘for / in’ loop. Resetting the field separator handily works around that
/bin/ls -1 — Directly use /bin/ls to bypass the common color-enabling aliases. Use -1 to force all files into one column. There’s no need to search for the beginning of the file name using this
lpr -r — The -r option deletes the file after it successfully prints. This is better than doing an ‘rm’ later since it only does the delete on a successful print.
0 comments:
Post a Comment