Monday, October 22, 2018

#1 2018-05-09 04:14:29 am

ldicroce
Member
Registered: 2017-11-25
Posts: 64

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 !

Offline

 

#2 2018-05-09 05:11:10 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5454

Re: Writing metadata

ldicroce wrote:

Which is the way to write/edit metadata to a file



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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2018-05-09 05:24:00 am

ldicroce
Member
Registered: 2017-11-25
Posts: 64

Re: Writing metadata

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 !

Last edited by ldicroce (2018-05-09 06:13:23 am)

Offline

 

#4 2018-05-09 06:57:32 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5454

Re: Writing metadata

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?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#5 2018-05-09 07:34:28 am

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2807
Website

Re: Writing metadata

ldicroce wrote:

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

Thanks !



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

Offline

 

#6 2018-05-09 07:40:42 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5454

Re: Writing metadata

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:

Applescript:

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:

Applescript:

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#7 2018-05-09 07:43:02 am

ldicroce
Member
Registered: 2017-11-25
Posts: 64

Re: Writing metadata

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

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)