Python Forum

Full Version: automatically printing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When I am photographying at an event, I need to print as I take the image.
When I photograph, I connect a cable from the camera to my macbook Pro(tethered).
The image, when taken goes to Adobe lightroom, is edited and saved.
I then need (I have been informed that Python is the tool) to read the folder and then send any JPG images in that folder to the connected printer.
So in approx 15 seconds, I have taken an image, it is edited, saved in a folder and then printed.
I do something like this, but on command, not automatically, to convert .xlsx files to pdf and then send them to the printer.

Apple computers use a Unix based system, I believe, so this script will send jpgs to the printer you designate.

A Linux programme incron uses inotify to monitor changes to a specific directory. Any time you put a photo in there, it can trigger the bash script below. Read this.

Not Python though!!

Output:
#! /bin/bash # set your paths JPGfiles="/home/pedro/temp/*.jpg" backupPath='/home/pedro/backupJPGs/" for X in $JPGfiles do if test $X then echo "This is one of the files:" printf $X; echo "Now sending the file to the printer ... " # set your printer lp -d "EPSON-L380-Series" $X; # get rid of the jpg after sending to the printer # or move it to backupPath # mv $X $backupPath echo "Junking the jpeg ... " rm $X; fi done
At least for Ubuntu, incron will save the incrontab file in /var/spool/incron/

First you need to add yourself to the allowed users in:

/etc/incron.allow

Just your user name on one line.

Then you can edit your incrontab with

incrontab -e (this calls nano editor on my system)

I put this:

Quote:/home/pedro/temp IN_MODIFY /home/pedro/myBashscripts/lp_JPGv2.sh

Now, if I copy a .jpg file to /home/pedro/temp it will immediately be sent to the printer of my choice, set in the bash script.
Just got a tip on a shorter method to do this: use wildcards:

Quote:$@ watched filesystem path (see above)
$# event-related file name

Make the incrontab like this:

Quote:/home/pedro/temp IN_MODIFY lp -d "EPSON-L380-Series" $@/$# && rm $@/$#;

Then, any photo arriving in the directory will immediately be sent to the printer and deleted. (Could save it somewhere if desired.)

Are my eyes failing, or has everything gone black??