Setting the metadata of a PDF in Bookends
Metadata of PDFs can be handy to have. For example in DevonThink the metadata of a PDF can be displayed in column view and give you more information than can be gleaned from the title alone. An example of how I store my PDFs in DevonThink in column view is:
In the three column view I typically have the name of the PDF (Author Date), the article title, authors, Spotlight comment, tags and link to the reference in Bookends. While it is possible to enter the metadata in Devonthink through the use of the ⇧⌥⌘P shortcut I tend to do one of two things.
The first approach that I might take is to highlight the title of the PDF in DevonThink and then click on a script button that I have set up in my toolbar called ‘Set title’. It triggers the following script:
-- Script to change the metadata title to clipboard contents
-- Note - requires ExifTool to be installed in /usr/local/bin
-- Get the contents of the clipboard and reformat as a single line of text if carriage returns are present
set titleClipboard to the clipboard as text
set titleList to paragraphs of titleClipboard
set titleName to ""
repeat with i in titleList
set titleName to titleName & i & space
end repeat
set titleName to titleName as text
-- Format titleName as title case
set titleCaseName to do shell script "python -c 'str = \"" & titleName & "\"; print str.title()'"
-- Get the path of the selection
tell application id "DNtp"
try
set theSelection to the selection
if the selection is {} then error "Please select something"
set pdfPath to path of the first item of theSelection
end try
end tell
-- Set metadata title
do shell script "/usr/local/bin/exiftool -title=" & quoted form of titleCaseName & " -overwrite_original " & quoted form of pdfPath
Essentially this script takes the clipboard, converts the clipboard to title case and then uses a command line tool called Exiftool to set the metadata of the PDF.
In my second approach I would have imported the reference into Bookends and I use the Bookends data to set the PDF metadata - namely title and author. This approach works if PDFs in Bookends are stored in a folder that is indexed by DevonThink. I have created an Alfred workflow that I trigger with a keyboard shortcut. The Alfred workflow is available on my Github page. This workflow requires Exiftool as well as setting up a Bookends format called ‘path’ with only the symbol ‘m’ in the Field Order as pictured below: