Print photo at 4x6 when it appears in a folder

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

I'm trying to figure out a way to print photos at 4x6 automatically as they appear in a folder.

My conditions (which are working fine) are

"Date Last Modified is after Date Last Matched"
"Kind is Image"

I've found that the shell script
Code: Select all
lp -o media=Custom.4x6in filename.jpg
does exactly what I want, but I can't figure out how to pass the filename to the script in Hazel. I found a few posts on the forums suggesting something like

Code: Select all
LONG_FILENAME="$1"
echo "Name with full path: $LONG_FILENAME"
echo "Name with only filename: $(basename $LONG_FILENAME)"


But that doesn't seem to be working for me (I'm getting a "non-successful error code 1"). I tried printing the value of $1 to a file, and it seems that it's the actual image itself (I got a lot of gibberish) rather than the path to the image.

Does anyone have any suggestions?
ryangiglio
 
Posts: 2
Joined: Fri Apr 26, 2013 10:00 am

You're on the right track, but you're missing quotes around LONG_FILENAME, so it would be something like this:

Code: Select all
lp -o media=Custom.4x6in $(basename "$1")


However, you probably don't need the basename here at all because lp can accept full file paths, so long as they are also quoted:

Code: Select all
lp -o media=Custom.4x6in "$1"




Note that the reason we have to do this is lp and other utilities separate their CLI commands by spaces, so effectively:

Code: Select all
lp -o media=Custom.4x6in "$1"


Becomes this:

Code: Select all
[0] -o
[1] media=Custom.4x6in
[2] "$1"


So, if you have spaces in your path of "$1", for example Showing you/a test/filepath name.jpg, you're actually asking lp to do this:

Code: Select all
[0] -o
[1] media=Custom.4x6in
[2] Showing
[3] you/a
[4] test/filepath
[5] name.jpg


And it does not understand what the command "Showing" is, nor does it understand the file "Showing". That's why it'll fail unless you quote your spaces to give it:

Code: Select all
[0] -o
[1] media=Custom.4x6in
[2] "Showing you/a test/filepath name.jpg"
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

That's exactly what I needed. Thank you! Such a simple thing as putting quotes around it.
ryangiglio
 
Posts: 2
Joined: Fri Apr 26, 2013 10:00 am

I want to lean that, can anyone tell me mor or give me a full sample , please :)
dradio
 
Posts: 2
Joined: Tue Oct 25, 2016 11:14 pm


Return to Support