version 12.40 on windows command line
The code at the bottom works in all cases to fill the MWG:Description tag from the Photoshop Headline tag if it is used, or one of the City + Location / State / Country tags - choosing the lowest one filled.
However if I start with -MWG:Description<${MWG:Description;
If the MWG:Description tags do not already exist they are created (XMP-dc:Description & Exif-IFD0:ImageDescription - but empty without having the text copied from Headline or location tags.
If I run the command again (ie the MWG:Description tags exist) - the text is copied as I expect.
I struggle with the -tagsfromfile and advance formatting documentation to work out whether this is expected (or is just a quirk of using MWG:Description) - and I have a workaround, but thought I'd post this to help others / see if there is a better way of doing what I want.
exiftool "-MWG:Description<${Filename; { my $mydesc=$self->GetValue('MWG:Description');
my $myhead=$self->GetValue('XMP-Photoshop:Headline');
my $mycountry=$self->GetValue('MWG:Country');
my $mystate=$self->GetValue('MWG:State');
my $mycity=$self->GetValue('MWG:City');
my $mylocn=$self->GetValue('MWG:Location');
if( length($myhead)) { $_ = $myhead; }
elsif( length( $mycity)) {$_ = $mycity;
if( length( $mylocn )) {$_ = $_ .' '. $mylocn; } }
elsif( length( $mylocn)) {$_ = $mylocn; }
elsif( length( $mystate)) {$_ = $mystate; }
elsif( length( $mycountry)) {$_ = $mycountry; }
else {$_ = undef; }
}
}" -fast2 -use mwg -ext DNG -charset filename=utf8 -charset exif=utf8 -progress -m .
Remove the -m (-ignoreMinorErrors) option (https://exiftool.org/exiftool_pod.html#m--ignoreMinorErrors). From the docs
Note that this causes missing values in -tagsFromFile, -p and -if strings to be set to an empty string rather than an undefined value
Wow, such a complex example, it took me a while to figure out what you were trying to do. But I think your problem is simple: The advanced formatting doesn't have any affect on a non-existent tag, even if the -m option is used. This is correct. It is like this because I never anticipated people would want this, and it would require specialized code to achieve.
- Phil
Phil,
Many thanks for confirming my observation is a (non-) feature rather than a bug and confirming it isn't because of the MWG:
I confess I'd missed that part of documentation of -m - but had tried both with and without -m. As I couldn't see anything stopping me using ${filename which must exist, rather than any other tag which might not, I thought it worth posting this.
I've been using exiftool for probably 10 years (through geosetter mostly and exiftoolgui) building commands with -if .... -execute pairs but they becuase of multiple read / write passes thought the file they take a while to run.
After finding the ability to write Perl within a command last weekend I thought If .. Then .. Else would elimate the multiple passes and had to test it - and to me this is easier to understand than the -if conditions i had used before.
If I find a use for Perl's Switch within my workflow i'll post that too.
Nigel
Hi Nigel,
This is a very extreme use of the advanced formatting feature, and it isn't really meant for something like this. For really complicated logic like this you should look into creating a user-defined Composite tag in your own config file (https://exiftool.org/config.html).
- Phil
Phil,
Thanks for the words of caution - I confess I've looked at config files a couple of times but was scared by them - now I've got 3 functions I need working using advanced formatting I'll stick with them until they break, but will also investigate config files again (this time with a bit more background knowledge)
Also I've circumvented the glitch I had writing to a non-existent tag with the -m option set (which I need because of lots of bad maker notes warnings)