IF clause not working correctly under Windows, works on Mac

Started by Harald, March 09, 2017, 10:09:59 AM

Previous topic - Next topic

Harald

I have the following statement working well on Mac, but ignoring the "flag" set by the -usercomment field and thus re-applying the script each time it runs to ALL files
WINDOWS:exiftool -m -if "not $usercomment eq 'processed'" "-xmp:description<${xmp:description} - ${xmp:location}, ${xmp:city}, ${xmp:country}; Photographer: ${xmp:creator}; ${exif:createdate}" -d %Y-%m -usercomment='processed' .
MAC: exiftool -m -if 'not $usercomment eq "processed"' '-xmp:description<${xmp:description} - ${xmp:location}, ${xmp:city}, ${xmp:country}; Photographer: ${xmp:creator}; ${exif:createdate}' -d %Y-%m -usercomment="processed" .

The idea obviously is to concatenate several fields into the description field, but only one time.
On Windows, even though the -usercomment field is updated, it re-runs the script.
Thanks a lot in advance for your help.

Phil Harvey

Your condition will fail if $userComment is not defined.  What you need is this:

-if 'not defined $userComment or $usercomment ne "processed"'

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

Harald

Thanks a lot Phil. If I understand the command correctly, my command should have failed on the first run, when the -usercomment was not defined. Which it did not. What failed was ignoring processed files on the second run, where the -usercomment field was already set to "processed".
In any case of course good to include the extra clause to take care of undefined fields.

Unfortunately the "if" still does not work properly. Although the -usercomment field is set to "processed" the command goes through all images and re-writes the description, making it a longer each time and replicating photographer, etc.

Now I had an intuition and I replaced the single quotes in the 'processed' with doubled quotes "processed" in the IF clause. And tata, it worked. Strange enough the assignment -usercomment='processed' at the end of the command works even with single quotes. This Windows can drive one crazy ...

So, problem solved. Thanks a lot again for your help.

kind regards,
Harald

Harald

UPDATE: I am afraid that was not it. I have done more tests and the condition fails each time when I have it in double quotes ("processed"). I also removed the first part (unspecified) but it still failed.
Maybe I should mention that the script runs on Windows server, not Windows 7, 8 or 10?
So the summary is: with double quotes it fails each run, with single quotes it always runs.

I hope you can solve this riddle :)


Phil Harvey

On Windows, the command should be:

exiftool -m -if "not defined $usercomment or $usercomment ne 'processed'" "-xmp:description<${xmp:description} - ${xmp:location}, ${xmp:city}, ${xmp:country}; Photographer: ${xmp:creator}; ${exif:createdate}" -d %Y-%m -usercomment="processed" .

And you must double the "%" characters if run from a .bat file.

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

Harald

Thanks a lot, Phil. That was the one "''" combination that I had not tried :)
Works just fine now.