How to 'enclose' tags when importing a PDF

I want to automate the ingestion of a bunch of PDFs where I do have the PDFs themselves as files in a folder and in one accompanying CSV file some metadata to each PDF: URL, keywords, and a published date.

I want to import the PDFs into Devonthink and bring over the metadata:

  • For the URL I worked out I can put it in the com.apple.metadata.kMDItemWhereFroms field of the macOS file metadata
  • The published date carries over when I set the modified date of the PDF file to it.

How can I carry over the keywords to the Devonthink tags of the PDF ?

There’s kMDItemKeyword(s?) field, I think. If that does not work, a script should

1 Like

You could use the extended attribute for Finder tags (com.apple.metadata:_kMDItemUserTags)

2 Likes

Thanks. Will try both.

tell application id "DNtp"
	if (selected records) is {} then return
	set theKeywords to |kMDItemKeywords| of (get meta data of selected record 1)
end tell
2 Likes

Here my results:

  • com.apple.metadata:_kMDItemUserTags: Tags saved under this attribute appear in Finder – but not in DEVONthink.
  • com.apple.metadata:_kMDItemKeywords: Tags saved under this attribute appear neither in Finder nor in DEVONthink.

Maybe I have to use com.apple.metadata:kMDItemKeywords (without the “_”) to make that one work? (What is the “_” for anyway?)

Strange thing is: On Apple’s Metadata Attribute documentation page I could find kMDItemKeywords (which does not work), but I couldn’t find kMDItemUserTags which does work…

Is the option to import Finder tags enabled, see Settings > Files > Tags > Finder? And did you set the extended attribute before importing?

1 Like

That was the culprit! Had to enable it. Now it works. Thanks.

Now the relevance of the script dawns on me: Does it do the same what the Convert Keywords to Tags setting does?

Unless I’m overlooking something, that script does nothing pertinent. It sets a variable to the kMDItemsKeywords and then does nothing with that variable.

@chrillek is correct; the variable isn’t used. It’s a code snippet showing how to query that type of metadata from a file with vanilla AppleScript.

1 Like