Setting list tags with an input file

Started by daap, November 19, 2017, 05:50:21 PM

Previous topic - Next topic

daap

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

StarGeek

From the docs on the -@ option:
"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).  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 and the -common_args option

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.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

daap

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.

Phil Harvey

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

StarGeek

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.jpg
Then 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
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

daap

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.

daap

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.

StarGeek

#7
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=UTF8


PH Edit: separated options into one argument per line in sample argfile
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

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

StarGeek

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

daap

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.

Phil Harvey

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

daap