-execute with -if

Started by msandersen, June 10, 2021, 05:03:19 AM

Previous topic - Next topic

msandersen

I've discovered that I can use -execute to run several exiftool commands in a row. I have a few conditional commands I use, my question is if the -if condition affects -execute in that if the condition is met, is it bypassed?
eg
exiftool ~/exiftool-FocalLengthIn35mmFormat.pl -if '$LensModel eq "18-35mm"' -@ ~/exiftool_Sigma_18-35mm.args - execute -if '$LensModel eq "50-150mm"' -@ ~/exiftool_Sigma_50-150mm.args -common_args /Directory
Here I'm first running a Perl script to calculate and add the focallengthin35mm tag to Sigma files, followed by 2 conditional statements to add metadata to 2 Sigma lenses.
So, will all 3 commands execute in sequence, or is it stopped at the first -if with a match?

Luuk2005

Every -execute does obey its own separate -options (including the -if's) and all options coming after -common_args.
So if your exiftool can directly execute .pl files???? Then Im thinking an -execute should come right after the file.pl
But there is also a typo in the command, so must also remove the space right before execute.

So then maybe looking more like...
exiftool ~/exiftool-FocalLengthIn35mmFormat.pl -execute
         -if '$LensModel eq "18-35mm"'   -@ ~/exiftool_Sigma_18-35mm.args   -execute
         -if '$LensModel eq "50-150mm"' -@ ~/exiftool_Sigma_50-150mm.args -common_args /Directory


exiftool ~/exiftool-FocalLengthIn35mmFormat.pl -execute -if '$LensModel eq "18-35mm"' -@ ~/exiftool_Sigma_18-35mm.args -execute -if '$LensModel eq "50-150mm"' -@ ~/exiftool_Sigma_50-150mm.args -common_args /Directory
Windows8.1-64bit,  exiftool-v12.92(standalone),  sed-v4.0.7

Phil Harvey

They execute in sequence.  A failed -if condition doesn't go past the -execute.  However, there is a $ok variable that you can use in the condition if you want to stop processing if the last command failed.

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

msandersen

Quote from: Luuk2005there is also a typo in the command
Ah yes, discovered that when I experimented with some other commands. I don't currently have any photos from these lenses to process.
Quote from: Phil Harvey on June 10, 2021, 06:57:17 PM
They execute in sequence.  A failed -if condition doesn't go past the -execute.  However, there is a $ok variable that you can use in the condition if you want to stop processing if the last command failed.

- Phil
So, you're saying if the first Lens check fails, it won't check for the 2nd lens and potentially execute it's arguments? That's the opposite of what I need; I need something like an if-elseif option were arguments are only run if a match for the lens is found.
So is the only option to execute them separately in the terminal or use something like a Perl script to run exiftool separately for each? The first command in the list above is my attempt at a Perl script cobbled together from other examples, I could simply modify it to add the other commands. I was hoping for one clean command chaining the statements.

Luuk2005

Every -execute will obey its own -options (including the -if) and all options coming after -common_args.
So you can use -if 'not $OK' or -if '$OK' to test the previous -if condition, as your condition to execute...

exiftool ~/exiftool-FocalLengthIn35mmFormat.pl -execute
         -if '$LensModel eq "18-35mm"'                         -@ ~/exiftool_Sigma_18-35mm.args   -execute
         -if 'not $OK and $LensModel eq "50-150mm"'  -@ ~/exiftool_Sigma_50-150mm.args  -common_args  DIR

If $LensModel==18-35mm, not $OK fails, so this would be enough to prevent executing your -@ ~/exiftool_Sigma_50-150mm.args file.
If $LensModel!=18-35mm,  not $OK succeeds, so then tests $LensModel==50-150mm as the next-condition to execute your 50-150mm.args file.
If needing more complicated conditional testing, Im thinking the perl does offer much more flexibility?
Windows8.1-64bit,  exiftool-v12.92(standalone),  sed-v4.0.7

Phil Harvey

Quote from: msandersen on June 11, 2021, 05:11:15 AM
Quote from: Phil Harvey on June 10, 2021, 06:57:17 PM
They execute in sequence.  A failed -if condition doesn't go past the -execute.  However, there is a $ok variable that you can use in the condition if you want to stop processing if the last command failed.
So, you're saying if the first Lens check fails, it won't check for the 2nd lens and potentially execute it's arguments?

Sorry.  I worded that badly.  I meant to say the failed -if doesn't affect the next command.  The -if condition only applies to the one command.  -execute commands are independent.

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

msandersen

Thank you Phil Harvey & Luuk2005, that clears it up. It should work the way I want it to then, that's great. I will shoot some test shots soon and test it.
Good to know how the $OK variable is to be used, but in this case I won't need it, as $LensModel either matches and the args are executed, or not. If there was a default set of metadata at the end, it would be useful.

The issue with the Sigma lenses is they put so little Exif data in the file, just things like aperture and shutter speed, no FocalLengthIn35mm. The only information they put in about the lens itself is LensModel, and just like the above, "18-35mm" for model, nothing about what make etc. So the Raw converter doesn't have enough to make a definitive match.

msandersen

I tested it out with some different commands, and it seemed to work as expected:
exiftool -config ~/exiftool_config -@ ~/exiftool-test.args -sep "<>" -execute -tagsfromfile %d%f.jpg -gps:all -xmp:all -iptc:all --iptc:Category --iptc:Sub-Location --iptc:SupplementalCategories '-xmp:CreateDate>exif:CreateDate' -ext raf -r -overwrite_original -common_args DIRECTORY
Notes:
I found -sep (which I use for Keywords) didn't work if in the .args file, so had to list it on the command line. -r and -overwrite_original are already in the args files, so not added to the -common_args
I use Photo Mechanic for import, and it doesn't write to compressed .Raf files, so I write the accompanying jpg metadata to the .Raf with this command.
When changing the creation date in Photo Mechanic, it adds it to XMP, but the exif is the old date, so I have'-xmp:CreateDate>exif:CreateDate' at the end, even though most of the time I don't change the time, only when shooting with 2 cameras and I sync, or forgot to change to summer time. xmp:CreateDate only exists if Photo Mechanic writes it. I understand if xmp:CreateDate doesn't exist, it won't do anything regardless.

Phil Harvey

Quote from: msandersen on June 11, 2021, 12:41:55 PM
I found -sep (which I use for Keywords) didn't work if in the .args file, so had to list it on the command line.

This is FAQ 29.

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

msandersen

This is FAQ 29.

- Phil
[/quote]
Aah, makes sense. I experimented with -sep some time ago, I expect I just copied the command line format, all on one line, and found it didn't work. 2 lines, no quotes. I've modified my .args files accordingly to keep things neat.
Thanks