Using -TAG-=[VALUE] Conditional Tag Testing

Started by lewisn, March 31, 2016, 08:50:30 PM

Previous topic - Next topic

lewisn

Phil, I've spent quite a bit of time reading the on-line documentation, scanning the forum, and experimenting to try to better understand command-line behavior of -TAG-=[VALUE] testing.  I would appreciate your confirming a few things I've found and some guidance on a few points.  I start with the basics and work up to some more interesting cases.  (The first three examples are as shown in the "Writing Examples" in the documentation.)

C:>exiftool -EXIF:ImageDescription-=string test.jpg
This deletes the tag if it has the value of "string".

C:>exiftool -EXIF:ImageDescription-= -EXIF:ImageDescription=string test.jpg
This sets the tag to "string" only if it didn't already exist.  The first part sets up a condition on the following tag operation.

C:>exiftool -EXIF:ImageDescription-=string -EXIF:ImageDescription=newstring test.jpg
This extends the behavior of the preceding example to test for a particular string.   The tag is set to "newstring" only if the tag was originally "string"; otherwise it does nothing.

C:>exiftool -EXIF:ImageDescription-=string -IPTC:Caption-Abstract=anotherstring test.jpg
In this case, however, the second tag is set to "anotherstring" regardless of the test on the first string.  It appears that the tags have to match for the "-="conditional in the first argument to set a condition on the second argument.  [This has degenerated into two separate operations where: 1) The ImageDescription tag is deleted if it's value is "string", and 2) a separate simple stand-alone operation setting Caption-Abstract to "secondstring" unconditionally.]

It appears that it is not that the conditional statement operates on whatever follows as the next statement as I first thought, but rather it operates on a matching second tag if there is one.  Question: Is it in fact important that the argument with the "-+" test immediately precede the argument that's intended to be continually executed, or is it important only that they match?  (Perhaps it would even work if their order is reversed?  I do realize it's probably best to keep them next to each other and in the given order to avoid confusion.)

I also noted another behavior which I thought was interesting:
C:>exiftool -EXIF:ImageDescription-=string -EXIF:ImageDescription= test.jpg
In this case the tag is unconditionally deleted, apparently by the second statement, regardless of whether "string" is in the original tag or not.    I realize the second statement is not needed if what you are trying to do is conditionally delete the tag based on the test for "string".  The first part does this on its own if it stands alone.   I was confused for a while by this behavior, however, since I expected the conditional test of the first part to apply to the "-EXIF:ImageDescription=" operation since the tag names matched, consistent with behavior I found above.  As I say, this is not a problem, as long as you understand it.  It is interesting, though, that by simply adding another string after the final = sign in this example, then that part of the command becomes a conditional operation, where, as written, it is unconditional and deletes the tag unconditionally.

Comments?  Can you confirm the above behavior is as expected?  Hopefully I haven't missed something.   Thanks!  LewisN

Hayo Baan

I think you misunderstood the way this is supposed to work. The -= operator is not a condition. From the manual:
Syntax Result
-TAG= Deletes all occurrences of TAG
-all= Deletes all meta information! †
-GROUP:TAG= Deletes TAG only in specified group
-GROUP:all= Deletes all information in specified group
-[GROUP:]TAG=VALUE Sets value of TAG (only in GROUP if specified)
-[GROUP:]TAG+=VALUE Adds item to a list, shifts a date/time, or increments a number
-[GROUP:]TAG-=VALUE Removes item from a list, shifts a date/time, or deletes TAG if it has the specified value
-[GROUP:]TAG<=FILE Sets tag value from contents of specified file
† See the Writer Limitations for some limitations of this feature.


Does this clarify things?
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

Your understanding of the first few examples is good, but the following need clarification:

Quote from: lewisn on March 31, 2016, 08:50:30 PM
C:>exiftool -EXIF:ImageDescription-=string -IPTC:Caption-Abstract=anotherstring test.jpg
In this case, however, the second tag is set to "anotherstring" regardless of the test on the first string.  It appears that the tags have to match for the "-="conditional in the first argument to set a condition on the second argument.

No.  -TAG-=VAL says "only delete TAG if it has value VAL".  It has no effect on other tags, and it doesn't matter what argument comes after this on the command line.

Quote
C:>exiftool -EXIF:ImageDescription-=string -EXIF:ImageDescription= test.jpg
In this case the tag is unconditionally deleted, apparently by the second statement, regardless of whether "string" is in the original tag or not.

Right.  This is what ExifTool is thinking when it reads each argument from this command:

1. OK, he wants to delete EXIF:ImageDescription if it is equal to "string".

2. Hmmm.  Now he says he wants to delete EXIF:ImageDescription unconditionally.  OK, I'll ignore the other argument.

You can use the -v2 option to get more details about what is happening:

> exiftool -EXIF:ImageDescription-=string -EXIF:ImageDescription=xxx -v2 a.jpg
Deleting IFD0:ImageDescription if value is 'string'
Writing IFD0:ImageDescription if tag was deleted
...


> exiftool -EXIF:ImageDescription-=string -IPTC:Caption-abstract=yyy -v2 a.jpg
Deleting IFD0:ImageDescription if value is 'string'
Writing IPTC:Caption-Abstract
...


> exiftool -EXIF:ImageDescription-=string -EXIF:ImageDescription= -v2 a.jpg
Deleting IFD0:ImageDescription if value is 'string'
Deleting IFD0:ImageDescription
...


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