Help with if then statement, tying shoes

Started by Bill, December 19, 2016, 09:48:37 AM

Previous topic - Next topic

Bill

Hi, I am working on a project to create Finder tags, rename, and sort a photo library of 10 years worth of images. To do this, I am using Hazel for OS X.

In addition to the year and quarter shot (that's working fine), I am wanting to add Finder tags indicating the device on which the images were captured (iPhone or Nikon SLR). Hazel is not able to see the Make or Model tags from the EXIF data. So, my idea is to add a simple script that returns a TRUE value if the file being evaluated contains a matching string in the relevant tag. My rudimentary skills have gotten me this far:

exiftool -if '$Make =~ /Apple/i' $1

I feel like I am missing some syntax here, because I've included a condition but no action to take if the condition is true. How does the script pass 0 back to Hazel?

I realize this is probably something a student would learn in their first week of class, but I got all Cs in my sophomore year of college computer science 20 years ago and decided to leave programming to the smarter people.

 

Phil Harvey

This is a Hazel question.  You should be able to check the return code of a command executed from Hazel, but I don't know how to do this.  In a shell script, this is done by checking the value of "$?".

BTW, if you are just interested in the return code, and don't want any of the extracted information, I would add a dummy tag name to the command, like this:

exiftool -if '$make =~ /apple/i' -dummy $1

- 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 ($).

Bill

Thanks Phil.

Just to close this out for any future readers: it was in fact a Hazel issue (user error, actually!). I was trying to run the rule on a folder residing on NAS. When I tried it on a local folder, it worked fine. So I realized indexing was not enabled on the NAS. After entering the below command in Terminal, the NAS was indexed and the rule works as expected in Hazel, no script necessary.

mdutil /Volumes/name -i on

Although ExifTool was not the solution I needed, I am awestruck by its capabilities in the hands of those who know what they are doing, and am inspired to now learn Perl so I can take advantage of it in the future.

- Bill