Bookends/DTPro syncing: a possible workaround

Hi,
one of my biggest issue since I started using DTPro in conjunction with BookEnds was finding a way to make them ‘talk’ to synchronize my citations to DT. As BE is not scriptable that’s only a possible (and unidirectional) workaround). Bookends template is a very nice way of doing it but, as it copies relevant data from the view windows, it can’t retrieve all data I’d like to have in DTPro (especially keywords) and you can’t batch export references.
So what I thought was to export references in a ‘special’ export format (in Bookends), imported the .rtf file in DTPro and automatically split the file using a special character as text delimiter (previously inserted in the BE export format). The result is a file in DTPro with all data you may need from BE. You can then choose to tag the references according to the BE keywords. As I’m a ‘dumb’ scripter all I did is hacking scripts from other users (see credits below). No debugging. Use and modify them at your own risk.

Here’s my workflow:

  1. create your custom format in BE.
    Mine is something like that:
    AUTHOR, TITLE, YEAR.
    see: ATTACHED.PDF [if you have wikilinks on, this will become a link to original pdf which in my case is indexed in DTPro too]
    TAGS: Key1;Key2; [the asterisks are needed to delimit keywords from the rest of the reference and semi-colon is needed to delimit each keyword from the next one]

     [bookends://sonnysoftware.com/@](bookends://sonnysoftware.com/@) 
    
     &&&  [b][That's the text delimiter I chose which allows to split the original export file; as the script below asks what delimiter to use you can set it to whatever you like][/b]
    
  2. export it as an .rtf in DTPro (or just copy it in a new document in DTPro)

  3. split the file with this script provided by kalisphoenix and slightly modified http://www.devon-technologies.com/scripts/userforum/viewtopic.php?f=20&t=3479

--split file in multiple files by kalisphoenix
	tell application "DEVONthink Pro"
   set theSelection to the selection
   if theSelection is {} then error "Please select some contents."
   display dialog "Enter the desired text delimiter (or nothing to break at each paragraph):" default answer "" buttons {"OK"} default button 1
   set SplitPointRegEx to text returned of the result
   if SplitPointRegEx is equal to "" then set SplitPointRegEx to ASCII character 10
   set OldDelimiters to AppleScript's text item delimiters
   repeat with CurrentItem in theSelection
      set AppleScript's text item delimiters to SplitPointRegEx
      set theSource to the plain text of CurrentItem
      set RepeatCount to 0 as integer
      set TotalCount to (count each text item of theSource) as integer
      repeat until RepeatCount is equal to TotalCount
         set RepeatCount to RepeatCount + 1
         set CurrentText to (text item RepeatCount of theSource)
         if length of CurrentText is greater than 0 then
            create record with {name:CurrentText, type:txt, plain text:CurrentText}
         end if
      end repeat
   end repeat
   
   set AppleScript's text item delimiters to OldDelimiters
end tell

  1. now you have each reference exported from BE in a separate file and you can optionally batch-tag them selecting them and running the script below (thanks to Johannes Hoffmann; slightly modified by me):
-- Bookends2tags
-- this script converts tags in imported Bookend references to DTP tags
-- Each reference should be one file and the keywords should be separated by semicolon and enclosed by *
-- Example (thanks to nestor): Alberdi Juan Bautista, “Ideas Para Un Curso De Filosofía Contemporánea” in Zea Leopoldo (a cura di), Fuentes De La Cultura Latinoamericana, México, Fondo de Cultura Economica, 1993. [LINGUE: 6. AL.9, 307 (I-II-III)] *philosophy; Latin America; History of culture*

-- Written by Johannes Hoffmann 2009
-- Use and modify at your own risk.
tell application "DEVONthink Pro"
	
	set theSelection to the selection
	repeat with theRecord in theSelection
		-- extract the text between the two asterixes
		set theText to plain text of theRecord
		set Start to offset of "*" in theText
		set theTags to (texts (Start + 1) thru -1 of theText)
		set Ende to offset of "*" in theTags
		set theTags to (texts 1 thru (Ende - 1) of theTags)
		
		-- split into single tags by semicolon
		set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ";"}
		set theTagList to text items of theTags
		set AppleScript's text item delimiters to od
		
		--
		set newTags to (parents of theRecord) & theTagList
		set the tags of theRecord to newTags
		repeat with theRecord in theSelection
			
		end repeat
	end repeat
	
end tell

  1. the result is a single reference file with all informations from BE you decided to output and tagged with BE keywords:

If you index the bookends attachment folder in DTPro you may want to include in the BE export format the name of the attachment. Having wikilinks on, this will generate a automatic link to the pdf.

Obviously that’s just a first try which can modified to make the workflow more fluid and the resulting files more ‘elegant’ (for ex.: tags are still part of the text file as I couldn’t automatically delete them…)
Suggestions and comments are welcome! Sorry for my poor english
:wink: