1

I'm running the following command to add multiple keywords to an image:

exiftool  -keywords+="Flowering"  -keywords+="In Flower"  -keywords+="Primula vulgaris"  -overwrite_original "/pictures/Some Folder/P4130073.JPG"

However, I've noticed that if I do this for an image which already contains a particular keyword, then it'll get added a second time.

How can I ensure that keywords are added only if they're already missing, and that if they exist, it'll do a no-op (and ideally leave the file untouched). I've read a few questions on the forum and the docs, but NoDups docs isn't clear to me (I'm an exiftool n00b) and all the answers I've found only process a single keyword addition.

For an added bonus, if the 'exists' check could be case-insensitive, so much the better (e.g., so that if I'm doing keywords+="Flowering" and the image already has the keyword "flowering", nothing will be done.

I also need this to work on Linux, MacOS and Windows (I know the quotes can complicate things!).

Webreaper
  • 509
  • 4
  • 18

1 Answers1

4

See Exiftool FAQ #17

To prevent duplication when adding new items, specific items can be deleted then added back again in the same command. For example, the following command adds the keywords "one" and "two", ensuring that they are not duplicated if they already existed in the keywords of an image:

exiftool -keywords-=one -keywords+=one -keywords-=two -keywords+=two DIR

The NoDups helper function is used to remove duplicates when they already exist in the file. It isn't used to prevent duplicates from being added in the first place.

StarGeek
  • 4,948
  • 2
  • 19
  • 30
  • Thanks. I'd seen that, but based on a forum post about it, I'm worried about this bit: "To prevent duplication when adding new items, specific items can be deleted then added back again in the same command." - if my understanding is correct, removing and adding won't result in a no-op, but the file will always get touched (see here: https://stackoverflow.com/questions/42365424/exiftool-prevent-duplicate-iptckeywords-xmp-dcsubject-when-using-add). Is that correct? That said I found this which seems to explicitly describe your solution: https://exiftool.org/forum/index.php?topic=10116.0 – Webreaper Apr 27 '21 at 18:45
  • Actually, for the process I'm running, it's fine for the file to be touched even if the duplicate tag means it's a no-op, because other dependencies rely on the date/time of the file changing to know it's been successfully processed. So I'll mark this as answered. Thanks! – Webreaper Apr 27 '21 at 19:55
  • 1
    It's not something I've checked to see if the file is touched or not, but the [`-P` (`-preserve`) option](https://exiftool.org/exiftool_pod.html#P--preserve) (uppercase P, lowercase is a different option) will preserve the system timestamps. – StarGeek Apr 28 '21 at 00:21
  • 1
    Myself, I'm lazy. I don't worry about duplicate keywords until I'm done with the folder. Then I just run the `NoDups` to clean up the mess as the last step. – StarGeek Apr 28 '21 at 00:23
  • Yeah, unfortunately this is an automated background process which will run on half a million photos (it's part of my app here: http://github.com/webreaper/damselfly), so I want to try not to add dupe keywords inadvertently, because the cleanup will be a nightmare. ;) – Webreaper Apr 28 '21 at 12:11