Writing metadata

Which is the way to write/edit metadata to a file (I mean filling the “More Info” section with the text I want)?

Thanks !

It’s not really yours to write. That information is written to the Spotlight database by the appropriate Spotlight importers.

Perhaps I can give a better answer if you can explain what you’re wanting to do.

Scientific PDFs have in the “More Info” section additional information, such as Title, Pages, Authors, Description, etc.
Often - but not alway - they miss an information which I use to catalog them: the DOI (Digital Object Identifier).

I was planning to include it (when is missing). This is basically the reason why I need to edit the More Info.
Is that possible?
If it is too complicated, I could still include it in the “Comments”, which is less elegant, since some file will have it in the More Info while other in the Comments …
But, again if it is too complicated, don’t worry …

Thanks !

PDFs are a bit different, in that they can store metadata internally, which the Spotlight filter picks up and can then display. So it’s possible to to modify a PDF accordingly – it just depends a bit on how the metadata is being stored. Can you email me a sample PDF that shows the correct information?

To answer the question in general. You have to write your own metadata import plugin. The system will load and use the plugin when it seems to be fit. You can find more about it here

OK, so what you want to change is what appears as the Description in the Finder’s Get Info window, which is confusingly the Subject attribute of a PDF.

So there are two approaches. One is to use AppleScriptObjC to modify the PDF, like this:

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "Quartz"

set thePath to POSIX path of (choose file)
-- get PDF 
set anNSURL to current application's |NSURL|'s fileURLWithPath:thePath
set theDoc to current application's PDFDocument's alloc()'s initWithURL:anNSURL
-- get existing attributes
set theAtts to theDoc's documentAttributes()'s mutableCopy()
-- modify attributes, and set document to modified copy
theAtts's setObject:"New description" forKey:"Subject" -- change description to suit
theDoc's setDocumentAttributes:theAtts
-- write to disk
theDoc's writeToFile:thePath -- overwriting! Perhaps you should write to a separate file

The catch is that this actually writes a whole new PDF using Apple’s Quartz PDF engine, which might result in changes to the appearance of some PDFs, depending on their source.

The other option is to use Acrobat Pro, like this:

set theFile to (choose file)
tell application id "com.adobe.Acrobat.Pro" -- Adobe Acrobat.app
	open theFile
	set info active doc key "Subject" value "New description" -- change description to suit
	close active doc saving yes
end tell

Thanks a lot!
I will test both options and check which is more “conservative”
L.