batch-filexmpexiftooliptc

exiftool prevent duplicate iptc:keywords/xmp-dc:subject when using add +=


problem:

When i have a jpg whith iptc:keywords=holliday and i execute

the image has two "holliday" tags

to avoid duplicates i currently use

so "-=" has no effect if the keyword does not exist in the jpg yet.

however this method has the disadvantage that the jpg is always modified even if it is not necessary because the keyword is already there.

is there a more efficient axiftool-api call way to add a keyword/subject that only changes if it is neccessary?

background:

currently i am implementing meta-data sync for keywords/subjects between android and pc.

android generates a msdos batch script entry for every change made and i use an exiftool based bat script to apply the metadata changes on the pc side

since the pc Keyword changes can come from different android devices Keywords must be added/removed and cannot be completely set.


Solution

  • exiftool.exe myImage.jpg -if "not $keywords =~ \"holliday\""  -IPTC:Keywords+=holliday
    

    If the keyword is not present, add it.

    edited to adapt to comments

    exiftool.exe ^
        -if "not $keywords =~ \"holliday\""  -IPTC:Keywords+=holliday ^
        -execute ^
        -if "not $keywords =~ \"ocean\""  -IPTC:Keywords+=ocean ^
        -common_args myImage.jpg