Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have added tags to all of my PDF documents, but the problem is, that these kind of tags are only supported by OSX (Mavericks), that means they are gone if I want to use the PDF on a e.g. windows or linux machine.

I'am looking for a solution to automatically write all my tags into the PDF as keyword metadata.

share|improve this question

1 Answer 1

Here's a start: Tag is a command line tool to manipulate tags in Mavericks. ExifTool is a command line tool for writing metadata into images. So you need to do something like this to glue them together in a command line function:

function tags2metadata(){ 
   tags=$(tag -N "$1");                
   exiftool -Keywords="${tags//,/, }" "$1";
   tag --add "$tags" "$1";
}

tags=$(tag -N "$1"); harvests the tags as a comma separated list (the -N option is to avoid it displaying the file name in its output), eg good,bad,ugly

exiftool -Keywords="${tags//,/, }" "$1"; adds the tags to the "Keyword" metadata field in the pdf metadata (the expression ${tags//,/, } replaces every comma in $tags with comma+space, so that they become separate keywords).

Now exiftool creates a new file with the name of the original file and renames the original; eg. foo.pdf is renamed to foo.pdf_original and a new file foo.pdf is created with the modified metadata. You can change this by adding -overwrite_original to the exiftool command like this:

exiftool -overwrite_original -Keywords="${tags//,/, }" "$1";

but I chose to just re-write the mavericks Finder tags to the new file using tag --add "$tags" "$1"; ($1 in a function stands for the input it is given).

So to use it, you could then open a terminal, type in the script above, cd to the directory with your pdfs in it and do:

for i in *.pdf
   do tags2metadata "$i"
done

If you open the new file and check for keywords, you should find all your Finder tags in there.

To install tags and exiftool I recommend Homebrew. Once you've installed it you just need to type brew install exiftool tag and it will do the necessary magic for you.

Please test this on files that you don't mind screwing up before you let it loose on your good stuff.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.