The Script
-- Script to Link Bookends Publication and DEVONthink Document
-- Created by Silverstone on 17.10.2019
use AppleScript version "2.7"
use scripting additions
-- Customize script
set BETitleFormat to "Your_format_for_QuickList.fmt"
set BEDTNameFormat to "Your_format_to_name_PDF_in_DT.fmt"
tell application id "DNtp"
set theDoc to item 1 of (get selection)
set DTID to (uuid of theDoc)
set dtURL to URL of theDoc
end tell
tell application "Bookends"
tell front library window
set thePub to item 1 of (get selected publication items)
set BEID to id of thePub
-- Creating a Group List
set theGroupList to {} as list
repeat with theGroup in (get group items)
set theItems to (publication items of theGroup whose id is BEID)
if theItems is not {} then
set end of theGroupList to (name of theGroup)
end if
end repeat
set AppleScript's text item delimiters to ";"
set theGroups to theGroupList as string
set AppleScript's text item delimiters to ""
set BETitle to format thePub using BETitleFormat
set BEDTName to format thePub using BEDTNameFormat
set n to offset of ":" in BEDTName
if n ≠ 0 then set BEDTName to text 1 thru (n - 1) in BEDTName
set n to offset of "?" in BEDTName
if n ≠ 0 then set BEDTName to text 1 thru (n - 1) in BEDTName
set n to offset of linefeed in BEDTName
if n ≠ 0 then set BEDTName to text 1 thru (n - 1) in BEDTName
set n to offset of return in BEDTName
if n ≠ 0 then set BEDTName to text 1 thru (n - 1) in BEDTName
set n to offset of "." in BEDTName
if n ≠ 0 then set BEDTName to text 1 thru (n - 1) in BEDTName
set beURL to url of thePub
set BENotes to notes of thePub
-- Data for Exiftool:
set AppleScript's text item delimiters to linefeed
set ExifAuthors to author names of thePub as string
set ExifKeywords to keyword names of thePub as string
set AppleScript's text item delimiters to ""
set ExifTitle to title of thePub
set ExifSubject to abstract of thePub
set user4 of thePub to DTID
set BEDate to date modified of thePub
end tell
end tell
tell application id "DNtp"
add custom meta data BEID for "bookendsid" to theDoc
add custom meta data theGroups for "groups" to theDoc
add custom meta data BEDate for "bemodified" to theDoc
add custom meta data BETitle for "bookendstitle" to theDoc
set comment of theDoc to BENotes
set name of theDoc to BEDTName
set ExifPath to path of theDoc
if dtURL contains "bookends://sonnysoftware.com/" or dtURL is "" then
if beURL is not "" then
set URL of theDoc to beURL
else
set URL of theDoc to ""
end if
end if
set theFileName to proposed filename of theDoc
end tell
-- Modifying Meta Data for PDF:
do shell script "/usr/local/bin/exiftool -title=" & quoted form of ExifTitle & " -author=" & quoted form of ExifAuthors & " -keywords=" & quoted form of ExifKeywords & " -subject=" & quoted form of ExifSubject & " -overwrite_original " & quoted form of ExifPath
tell application "Bookends" to set attachments of thePub to theFileName
Sync DT and BE record.scpt.zip (8.6 KB)
Putting Script to work
- Download this script to
/Users/YourName/Library/Application Scripts/com.devon-technologies.think3/Menu/Bookends/
folder. Create it if needed - Open Bookeds:
2.1. Create format (or use existing) for Publication full reference to store it in DT (for generation of quick lists of literature and etc.)
2.2. Create format for naming Devonthink PDF file. I use like ‘1st Author (year) Title’ - Open the script in Script Editor (or other script editing tool of your choice).
3.1. Under the ‘Customize script’ paragraph insert the exact names of these two formats, you created in Bookends - Check if
exiftool
command-line utility is installed to your system. Type in Terminalexiftool -h
. If not - install it (likebrew install exiftool
) - Relaunch DT to refresh script menu
- At the Bookends check that you don’t use user4 field (Settings / Refs tab / Labels). There will be saved UUID of the corresponding DT PDF.
That’s it. Select Ref in BE and corresponding PDF in DT and run the script
After running script several times, go to DT settings / Data tab and check if your new custom meta data has the right params:
bookendsid
is ‘Integer number’, format ‘Number’groups
is ‘Identifier’bemodified
is ‘Date and Time’bookendstitle
is ‘Multiline Text’
Give them human readable names and position in a comfortable place in inspector.
Done.