mac automator script to copy filename to pdf author + title metadata

1

Have been looking around and cannot find a simple automator solution to copy info of a pdf's filename to the pdf's author and title metadata. Many solutions are built upon pdftk, but that util doesn't seem to be available for the mac anymore.

Any suggestions? I am not interested in Calibre and similar, I need an automator workflow that I can use in the Finder.

user267985

Posted 2013-10-29T22:19:22.347

Reputation: 11

Question was closed 2013-10-31T01:50:58.677

Answers

1

You can install pdftk on OS X by using the installer from http://www.pdflabs.com/tools/pdftk-server/.

This adds (filename.pdf) to the end of the author and title:

for f in *.pdf;do pdftk "$f" dump_data_utf8|awk -v "f=$f" '/InfoKey: (Author|Title)/{print;getline;sub(/$/," ("f")")}1'|pdftk "$f" update_info_utf8 - output "new_$f";done

This updates the title:

echo $'InfoKey: Title\nInfoValue: new title'|pdftk input.pdf update_info_utf8 - output output.pdf

Another option is to use exiftool:

brew install exiftool;for f in *.pdf;do author=$(exiftool -p '$Author' "$f");title=$(exiftool -p '$Title' "$f");exiftool -Title="$title ($f)" -Author="$author ($f)" -overwrite_original "$f";done

Lri

Posted 2013-10-29T22:19:22.347

Reputation: 34 501

Ok, didn't know about exiftool; great will bake a workflow out of it! – user267985 – 2013-10-30T15:45:38.750