terminal command equivalent to Automator's 'set metadata pdf'

Hi,


When I make pdf docs I sometimes want to erase my name from the Author metadata, and put something into Title and so on.


I know that Automator has an action called set pdf metadata, which I have successfully used. But I would like a Terminal command that I could use instead.


Googling this question returns suggestions of downloading pdf-manipulation libraries which are too elaborate for me to use. I'm hoping that Automator is simply utilising a terminal command already built-in.


Is there such a command?


Diddles

Posted on Aug 31, 2013 12:27 PM

Reply
5 replies

Sep 1, 2013 5:02 AM in response to diddles1234

A bit of experimenting.


Given a file temp.pdf in the current working directory . . .


xattr -w "com.apple.metadata:kMDItemAuthors" "diddles1234" temp.pdf


writes the string "diddles1234" to the Authors metadata field of temp.pdf.


xattr -w "com.apple.metadata:kMDItemTitle" "newmetatitle" temp.pdf


writes the string "newmetatitle" to Title metadata field of temp.pdf.



However, if you try to put spaces into the string like this:


xattr -w "com.apple.metadata:kMDItemTitle" "new meta title" temp.pdf


the title field will not be changed to "new meta title". In fact, if you start with "original title" as the value of kMDItemTitle, successfully change it to "newmetatitle", and then later try to change it again to "new meta title", the value of kMDItemTitle reverts to "original title". The OS appears to "forget" the intermediate change to "newmetatitle".


As best I can figure, in the event of a failed xattr write command, the original kMDItemTitle is rebuilt from semi-redundant data within the PDF--but more experimentation would be required to prove it. (The same is true of kMDItemAuthors, by the way.) Quick take away: The first two commands above will work if you don't use spaces in the strings to be inserted into the metadata fields. Someone more proficient in UNIX may have a better solution or explanation.

Sep 8, 2013 2:22 AM in response to mns579

There seems to be a difference between PDF metadata and the file-system metadata. I can follow the procedure you list above, and successfully add extended attributes, which are listed in the ls -l@ option but when I open the pdf in Preview the title/author etc are still unchanged. It seems that PDF files (and MP3/4 etc) for that matter have metadata within the file itself: and that's the bit I need to change.



So I think I'll have to stick with opening Automator from the terminal, as per Linc Davis's suggestion.


Thanks, though!


Diddles

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

terminal command equivalent to Automator's 'set metadata pdf'

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.