ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Stephen Marsh on March 15, 2016, 03:24:31 PM

Title: Copy Mac OS Finder -api MDItemTags to Keywords?
Post by: Stephen Marsh on March 15, 2016, 03:24:31 PM
I am trying to copy Mac OS Finder -api MDItemTags to Keywords:

exiftool '-subject+<${api:MDItemTags}' '/Users/user/Desktop/file.jpg'

I am sure that I am making a basic error in syntax or tag names etc (I have cobbled this command together).
Title: Re: Copy Mac OS Finder -api MDItemTags to Keywords?
Post by: Phil Harvey on March 15, 2016, 04:29:38 PM
Hi Stephen,

MDItemTags is not a real tag (it is in the Extra tags documentation (https://exiftool.org/TagNames/Extra.html) only as a placeholder for all of the system tags starting with "MDItem"), and "API" is not a group name, but you have the correct idea.  To copy all tags with names beginning with "MDItem" into separate items in the Subject list, the command is:

exiftool -addTagsFromFile @ '-subject+<mditem*' FILE

- Phil
Title: Re: Copy Mac OS Finder -api MDItemTags to Keywords?
Post by: Stephen Marsh on March 16, 2016, 03:51:53 AM
Thanks Phil, that of course works – however it adds all of the mditem info, not just the "tag" component, which then requires all of the garbage to be taken out.

EDIT: Ah, I can indeed change mditem* to mditemusertags to retrieve only the (usertags) tags/labels. That helps! I did not realise that I was not specific in my original post, I was only interested in mditemusertags and not all mditem entries.

I also added the -overwrite_original_in_place command so that the original Mac metadata was not removed.

Thanks again!
Title: Re: Copy Mac OS Finder -api MDItemTags to Keywords?
Post by: Stephen Marsh on August 12, 2016, 08:20:57 PM
Revisited... I am now running Mac OS 10.11.5 and ExifTool 10.25:

exiftool -overwrite_original_in_place -addTagsFromFile @ '-subject+<mditemusertags' 'FILE'

Results in the following error:

Warning: Shift value for XMP-pdf:Subject is not a number - FILE
    1 image files updated


However, the XMP subject has not propogated to the IPTC keywords etc. Is my expectation incorrect that this should "trickle down" to legacy keyword types, even if I only explicitly wrote only to subject?

Results reported with ExifTool:

Subject                         : existing-keyword, Green, Red, Yellow, Green, Red, Yellow
Keywords                      : existing-keyword

The Mac Finder tags Green, Red, Yellow have been repeated twice in Subject however they are not added to the legacy keywords field.

The test file was a .JPG and I am sure that this used to work in the past on an older version of the OS and or ExifTool.
Title: Re: Copy Mac OS Finder -api MDItemTags to Keywords?
Post by: Phil Harvey on August 12, 2016, 09:31:08 PM
Hi Stephen,

ExifTool writes only what you tell it (with rare exceptions: the mandatory tags).  So if you want IPTC:Keywords to be written, you must do it yourself.

- Phil
Title: Re: Copy Mac OS Finder -api MDItemTags to Keywords?
Post by: StarGeek on August 12, 2016, 09:34:58 PM
Quote from: Stephen Marsh on August 12, 2016, 08:20:57 PM
Revisited... I am now running Mac OS 10.11.5 and ExifTool 10.25:

exiftool -overwrite_original_in_place -addTagsFromFile @ '-subject+<mditemusertags' 'FILE'

Results in the following error:

Warning: Shift value for XMP-pdf:Subject is not a number - FILE
    1 image files updated

If you want to avoid this error, you might want to use XMP-dc:subject, but it's a minor error and can be ignored.

QuoteIs my expectation incorrect that this should "trickle down" to legacy keyword types, even if I only explicitly wrote only to subject?

Exiftool is only going to write to tags that you explicity tell it to write to.  Normally, if you don't include IPTC:Keywords as a tag you want to write to, it's not going to be written to. 

You can change this behavior with the -use MWG (http://www.exiftool.org/TagNames/MWG.html) option.  In this case, when you include -use MWG, you would then write to Keywords and then IPTC:Keywords and XMP-dc:Subject will be updated (as well as CurrentIPTCDigest and IPTCDigest). 

Another possibility is create a your own shortcut tag.  For example, in my .exiftool.config file, I have this shortcut:
MyKeywords => ['XMP-dc:Subject','IPTC:Keywords'],.  So when I write to MyKeywords, both XMP:Subject and IPTC:Keywords are written.
Title: Re: Copy Mac OS Finder -api MDItemTags to Keywords?
Post by: Stephen Marsh on August 12, 2016, 10:24:47 PM
Thanks Phil, I might have become confused with how Adobe Bridge works!

I have been using -Subject for a long time with no reported errors, now for whatever reason I need to use -XMP-dc:Subject

Moving on...

Original file:
Subject: existing-keyword
Keywords: existing-keyword

exiftool -overwrite_original_in_place -addTagsFromFile @ '-XMP-dc:Subject+<mditemusertags' 'FILE'

Result:
Subject: existing-keyword, Green, Red, Yellow
Keywords: existing-keyword

All good so far!

If I try almost the exact same command, swapping out subject for keyword:

exiftool -overwrite_original_in_place -addTagsFromFile @ '-IPTC:Keywords+<mditemusertags' 'FILE'

Result:
Subject: existing-keyword
Keywords: Green, Red, Yellow

It has not appended the Finder labels/tags to the entry "existing-keyword" it has replaced this existing entry, however when using the same command for subject it did not replace, it appended. I have the + plus sign in both...so why the different result when they should both be the same?

So until I can get the same result with both Subject and Keywords, I can't really look into combining both into a single command with any confidence.

I did try your suggestion for the -use MWG option writing to Keywords, however due to the issues mentioned above my results are not as expected or perhaps I added the -use MWG in the wrong position. Could you please provide the entire command?
Title: Re: Copy Mac OS Finder -api MDItemTags to Keywords?
Post by: StarGeek on August 13, 2016, 01:19:22 AM
Quote from: Stephen Marsh on August 12, 2016, 10:24:47 PM
I have been using -Subject for a long time with no reported errors, now for whatever reason I need to use -XMP-dc:Subject

For some reason I was thinking this was new behavior, but it happens as far back as v 9.16 (the oldest version still on my machine). 

QuoteIt has not appended the Finder labels/tags to the entry "existing-keyword" it has replaced this existing entry, however when using the same command for subject it did not replace, it appended. I have the + plus sign in both...so why the different result when they should both be the same?

I can't seem to replicate your experience here, but then I'm using windows and have to replace mditemusertags with other tags.  Normal results using a string or a list type tag.  I do notice that your posted commands have fancy quotes ' ' and not regular quotes ' and that could have an effect on your results if the fancy quotes are appearing in your terminal commands.

QuoteI did try your suggestion for the -use MWG option writing to Keywords, however due to the issues mentioned above my results are not as expected or perhaps I added the -use MWG in the wrong position. Could you please provide the entire command?

Something like this should work:
exiftool -use MWG -overwrite_original_in_place -addTagsFromFile @ '-Keywords+<mditemusertags' 'FILE'
Title: Re: Copy Mac OS Finder -api MDItemTags to Keywords?
Post by: Stephen Marsh on August 13, 2016, 05:31:37 AM
Thank you for the reply StarGeek! My code uses straight quotes, it is just how the forum software changes them and I did not go back in again and make them straight again after the copy/paste.

I tried your code, this is the result after running:

exiftool -use MWG -overwrite_original_in_place -addTagsFromFile @ '-Keywords+<mditemusertags' 'FILE'

Warning: Ignored non-standard IPTC at JPEG-APP13-Photoshop-IPTC - FILE
Warning: [minor] Fixed incorrect list type for XMP-dc:Subject - FILE
    1 image files updated


Subject: existing-keyword, Green, Red, Yellow
Keywords: Green, Red, Yellow

So again, even though applied to the keyword as an addition +, it has incorrectly overwritten the existing keyword and added the Finder tags/labels – however for the Subject it has correctly appended the labels/tags.

I'll dig deeper and try a different test file, perhaps something is screwed up here...
Title: Re: Copy Mac OS Finder -api MDItemTags to Keywords?
Post by: Stephen Marsh on August 13, 2016, 05:47:59 AM
Warning: Ignored non-standard IPTC at JPEG-APP13-Photoshop-IPTC - FILE

There must have been something screwy with that test file!

I now have the correct result!

Subject: existing-keyword, Green, Red, Yellow
Keywords: existing-keyword, Green, Red, Yellow

Thank you Phil and StarGeek!