Hi,
I am trying to set keywords on images using exiftool with the -@ option and the following input file contents:
-P
-fixBase
-m
-overwrite_original_in_place
-EXIF:XPKeywords=Food
-XMP:Subject=Food
-XMP:LastKeywordXMP=Food
-IPTC:Keywords=Food
C:\Sandbox\IMG_20171115_193902.jpg
-P
-fixBase
-m
-overwrite_original_in_place
-EXIF:XPKeywords=Panoramas
-XMP:Subject=Panoramas
-XMP:LastKeywordXMP=Panoramas
-IPTC:Keywords=Panoramas
C:\Sandbox\IMG_20171116_132617.jpg
-P
-fixBase
-m
-overwrite_original_in_place
-EXIF:XPKeywords=Tech
-XMP:Subject=Tech
-XMP:LastKeywordXMP=Tech
-IPTC:Keywords=Tech
C:\Sandbox\IMG_20171116_151421.jpg
-P
-fixBase
-m
-overwrite_original_in_place
-EXIF:XPKeywords=Flora & Fauna
-EXIF:XPKeywords=Flora & Fauna - Birds
-XMP:Subject=Flora & Fauna
-XMP:Subject=Flora & Fauna - Birds
-XMP:LastKeywordXMP=Flora & Fauna
-XMP:LastKeywordXMP=Flora & Fauna - Birds
-IPTC:Keywords=Flora & Fauna
-IPTC:Keywords=Flora & Fauna - Birds
C:\Sandbox\IMG_20171116_151429.jpg
My expectation was that the first image would get 'Food' set as keywords, the second 'Panoramas' etc. However it turns out that all four images get all keywords used in this input file, so 'Food', 'Panoramas', 'Tech', 'Flora & Fauna' and 'Flora & Fauna - Birds'.
I am using Exiftool 10.67 (just freshly downloaded) on Windows 7 and 10.
Am I missing something?
Cheers,
Daap
From the docs on the -@ option (https://exiftool.org/exiftool_pod.html#ARGFILE):
"Arguments in ARGFILE behave exactly the same as if they were entered at the location of the -@ option on the command line"
So you're creating one single long command line with all these details. In the case of list type tags such as XMP:Subject and IPTC:Keywords, all the values will be written. In the case of string tags such as EXIF:XPKeywords, the last assignment will take precedence (see note 1 under tag assignment (https://exiftool.org/exiftool_pod.html#TAG---VALUE)). If you check EXIF:XPKeywords you will see that the value on all the files is "Flora & Fauna - Birds".
What you want to do is look at the -execute option (https://exiftool.org/exiftool_pod.html#execute-NUM) and the -common_args option (https://exiftool.org/exiftool_pod.html#common_args).
You will put an -execute command after you finish all the assignments for any file(s) or directory. Then any options you want to apply to all of the commands separated by -execute after the -common_args option.
For example, you would want to use -common_args -P -fixBase -m -overwrite_original_in_place as those options are shared by all.
So your arg file should look more like this:
-EXIF:XPKeywords=Food
-XMP:Subject=Food
-XMP:LastKeywordXMP=Food
-IPTC:Keywords=Food
C:\Sandbox\IMG_20171115_193902.jpg
-execute
-EXIF:XPKeywords=Panoramas
-XMP:Subject=Panoramas
-XMP:LastKeywordXMP=Panoramas
-IPTC:Keywords=Panoramas
C:\Sandbox\IMG_20171116_132617.jpg
-execute
<snip>
-IPTC:Keywords=Flora & Fauna - Birds
C:\Sandbox\IMG_20171116_151429.jpg
-common_args
-P
-fixBase
-m
-overwrite_original_in_place
One additional item to look at is the EXIF:XPKeywords tag. It isn't a list type tag like Subject and Keywords. It's a string tag which will have the keywords separated by a semicolon. After you set your initial XPKeywords, any additions would have to be added with something like:
"-XPKeywords<$XPKeywords;Flora & Fauna - Birds"
Overall, it and the other Windows XP tags are poor tags and are rarely used by any program. Even Windows gives other tags priority over them.
Sorry, but that does not work. AFAIK the -execute option is used when an input file is left open for Exiftool to read from using the -stay_open flag. I just use the file with -@.
Also, the problem is not that all files get the keywords of the last entry in the input file, but all keywords ever used in the entire file.
You're right about the EXIF:XPKeywords tag, I actually split it out on separate lines when I was testing things but that should go on one line.
The -execute option is used whenever you would press RETURN on the command line to execute the command.
Why do you say that StarGeek's suggestion doesn't work? Were there any messages?
- Phil
Quote from: daap on November 19, 2017, 08:49:43 PM
Also, the problem is not that all files get the keywords of the last entry in the input file, but all keywords ever used in the entire file.
Yes, again, read Note 1 that I linked above.
You seem to be under the assumption that the filename indicates the end of a entry. Filenames can be anywhere on the command line, even separated by other options. If my command is
exiftool -keywords=Key1 ./File1.jpg -keywords=Key2 ./file2.jpg -keywords=Key3 ./file3.jpgThen all three files are going to have all three keywords assigned to them.
Try this as your arg file:
-EXIF:XPKeywords=Food
-XMP:Subject=Food
-XMP:LastKeywordXMP=Food
-IPTC:Keywords=Food
C:\Sandbox\IMG_20171115_193902.jpg
-execute
-EXIF:XPKeywords=Panoramas
-XMP:Subject=Panoramas
-XMP:LastKeywordXMP=Panoramas
-IPTC:Keywords=Panoramas
C:\Sandbox\IMG_20171116_132617.jpg
-execute
-EXIF:XPKeywords=Tech
-XMP:Subject=Tech
-XMP:LastKeywordXMP=Tech
-IPTC:Keywords=Tech
C:\Sandbox\IMG_20171116_151421.jpg
-execute
-EXIF:XPKeywords=Flora & Fauna;Flora & Fauna - Birds
-XMP:Subject=Flora & Fauna
-XMP:Subject=Flora & Fauna - Birds
-XMP:LastKeywordXMP=Flora & Fauna
-XMP:LastKeywordXMP=Flora & Fauna - Birds
-IPTC:Keywords=Flora & Fauna;
-IPTC:Keywords=Flora & Fauna - Birds
C:\Sandbox\IMG_20171116_151429.jpg
-common_args
-P
-fixBase
-m
-overwrite_original_in_place
I figured it out; the -execute I added in was only added after the last file. When I changed it to between files as was the intention, it worked as expected.
Thanks guys. Great tool Phil, I have been using it for a long time.
Now I stumble into something else: if instead of C:\Sandbox in the example file given I use a filename with a non-standard character (like ë for example) then the first file is processed, but with all subsequent files Exiftool gives a 'file not found' error. It's almost as if the encoding is reset between files or something like that.
I am on Windows, and I call Exiftool with -charset UTF8 and -charset filename=UTF8. I call Exiftool with these parameters from a C# application, so I don't use Windows Command shell. The input file is written as a true UTF8 file from C# and gets a UTF8 prefix which is visible in an appropriate text editor.
Quote from: daap on November 20, 2017, 12:23:11 AMIt's almost as if the encoding is reset between files or something like that.
As Phil said
Quote from: Phil Harvey on November 19, 2017, 09:56:28 PM
The -execute option is used whenever you would press RETURN on the command line to execute the command.
If you have options that are common to all commands when using
-execute, use the
-common_args option. Based upon your posts, the last few lines of your arg file should be this
-common_args
-P
-fixBase
-m
-overwrite_original_in_place
-charset
UTF8
-charset
filename=UTF8PH Edit: separated options into one argument per line in sample argfile
@StarGeek: Remember that -common_args may not be used inside an ARGFILE:
-common_args
Specifies that all arguments following this option are common to
all executed commands when -execute is used. This and the -config
option are the only options that may not be used inside a -@
ARGFILE. Note that by definition this option and its arguments
MUST come after all other options on the command line.
- Phil
Ahh, my mistake. My apologies then.
That works, thanks!
Just for the record, make sure the -@ option comes before -common_args, otherwise Exiftool complains about recursive processing.
The only thing I don't get is why I actually needed the combination of -common_args with charset UTF8, since UTF8 is Exiftool's default anyway. But hey, I got what I wanted...
Thanks for your help.
-charset UTF8 is the default, so specifying this is not necessary.
-charset filename=utf8 is necessary because the default filename character set is not defined.
- Phil
That explains it, thanks.
Daap