Copy Mac OS Finder -api MDItemTags to Keywords?

Started by Stephen Marsh, March 15, 2016, 03:24:31 PM

Previous topic - Next topic

Stephen Marsh

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

Phil Harvey

Hi Stephen,

MDItemTags is not a real tag (it is in the Extra tags documentation 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
...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 ($).

Stephen Marsh

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!

Stephen Marsh

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.

Phil Harvey

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
...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: 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 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.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Stephen Marsh

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?

StarGeek

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'
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Stephen Marsh

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...

Stephen Marsh

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!