Newbie trying to get Hazel to run a rule

Started by james.v, March 14, 2023, 07:39:41 PM

Previous topic - Next topic

james.v

I'm trying to get Hazel to run a rule based on whether exiftool finds it has a particular keyword.

I'm already using Keyboard Maestro to add the keywords using the shell script.

/usr/local/bin/exiftool ^ "," -XMP:Subject="$KMVAR_Local_myexiftags" -overwrite_original -P "$KMVAR_Local_filePath"
But Hazel requires a boolean output and I don't know how to do that.

Screenshot 2023-03-14 at 23.37.38.png

Can someone help?
I've been searching and found some stuff about regex but it doesn't help me generate the output that I need for Hazel.

Thanks in advance



Phil Harvey

From the exiftool application documentation:

EXIT STATUS
       The exiftool application exits with a status of 0 on success, or 1 if
       an error occurred, or 2 if all files failed the -if condition (for any
       of the commands if -execute was used).


... which I think is exactly what you need.  No?

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

james.v

Quote from: Phil Harvey on March 14, 2023, 09:55:23 PMFrom the exiftool application documentation:

EXIT STATUS
       The exiftool application exits with a status of 0 on success, or 1 if
       an error occurred, or 2 if all files failed the -if condition (for any
       of the commands if -execute was used).

... which I think is exactly what you need.  No?

- Phil

Thanks. Yes. It's just that I don't think my code is right. I have a photo with the subject exif keyword "Summer" in the folder but it's not working (hard to work out what's going on inside Hazel). Is my shell script right?

exiftool $1 -if "$Subject=~/(^|, )Summer(, |$)/" -xpcomment="0"




Phil Harvey

You need to use single quotes in unix shells (read my sig).

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

james.v

Brilliant. It's now working (I think) but it generates another file called filename.png_original
As far as the shell script is concerned it's only meant to pop out a yes or a no, right?

Just writing that down I've realised that I guess those files are its 0s and 1s right?

Phil Harvey

You are setting -xpcomment="0" so the file is edited and this XPComment is added.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

james.v