DT3 and Bibdesk

Ok, so now I am testing how would the integration between BibDesk and DEVONthink 3 look like.

Because I can download any reference using the Reference Importer Alfred workflow to download the bibtex, and then quickly sync the reference information to the DT3 record custom metadata.

With my rudimentary scripting skills, I could come up with one to move metadata from BibDesk to DNtp:

And from DNtp to BibDesk:
(This is for occasions in which the metadata is already filled up on DT3 but you also want it in BibDesk)

Edited. I removed the script and will post it back soon.

There are a few idiosyncrasies in the two scripts (see the name of my custom MD fields, for instance). But perhaps it can be useful as a starting point if someone else with actual Applescript knowledge wants to try something.

Ideally they could converge to one single script, but I still lack the skills (and by now, the time) to attempt it.

1 Like

Just cooked up this which is a bit more elegant IMHO. This does require you to set up an exportMarkdown template in BibDesk first. Or you can comment out those two lines. Next steps would be to add existing BibDesk URLs and linked files as well.

    tell application "BibDesk"
	set s to selection of document 1
	repeat with i in s
		-- get the cite key and create a new DT group with the same name and a link back to the BD record
		set ck to cite key of i as string
		set c to ""
		-- get the markdown citation
		export document 1 using template "exportMarkdown" to clipboard for i
		set c to the clipboard
                -- create the new group
		tell application id "DNtp"
			tell think window 1 to set myGroup to create location ck
			add custom meta data ck for "Cite Key" to myGroup
			add custom meta data "x-bdsk://" & ck for "BibDesk URL" to myGroup
			-- add the markdown citation to the new group
			create record with {name:ck & " Markdown reference", plain text:c, type:markdown} in myGroup
			-- get the DT link to add to the BD record
			set theDntp_Link to reference URL of myGroup
		end tell
		-- get all the fields from the BD item
		set theFields to fields of i
		-- add them all to the new DT group
		repeat with f in theFields
			set fn to name of f
			set fv to the value of f
			tell application id "DNtp"
				add custom meta data fv for fn to myGroup
			end tell
		end repeat
		-- add the DT link to BibDesk
		add theDntp_Link to i
	end repeat
end tell
1 Like

Here’s the BibDesk markdown export template that I use with this, btw. See https://sourceforge.net/p/bibdesk/wiki/Templates/ for details on how to set up a template in BD.

Thank you for sharing it. As far as I can see our scripts serve two different purposes. Perhaps I should have made clear that…

  1. I have the PDF file on DT3 and that…
  2. …what I want to do is to get the meta data from a BIBDESK reference into the MD fields of my PDF file on DT3.

Here are some screen caps of what I am doing.

The problem:

I have a pdf file on DT3 without the appropriate metadata.

First I will look for the reference using the Reference Importer workflow on Alfred.

The reference will then open on BibDesk. While having my pdf file selected on DT3, I will select the imported reference and run the script. The metadata will then get transferred.

After reviewing the metadata and making sure everything is in place, I then run the Add Reference smart-rule script posted on this thread.

It will then generate the complete reference to use as the file name. It will also add the bibkey as an alias.

It certainly could be improved, but it is already much better than what I was doing before using Bookends.

1 Like

So the BibDesk entry - or more specifically the CSV output from BibDesk - doesn’t contain the appropriate data yet?

Yeah, the script I posted is oriented towards mirroring an existing BD database in DT, but it can be easily modified to add the current BD fields to the current DT selection.

Changing the name to the full reference is trivial as well - just modify the exportMarkdown template to put it all on one line as in your example above then use the export results in the create location command.

Likewise you could add that result to a custom metadata reference field instead of adding it as a separate Markdown document.

Whether you end up using BibDesk or Zotero or Bookends, you’re going to want to farm the reference generation off to your bibliographic software. The script you link to is going to be a mess to change if you need to produce a bibliography in a different format, whereas any of those programs will have ready-made templates and/or CSL to produce the citations.

I’d also recommend using containing groups rather than acting on the PDFs directly. Eventually you will encounter a situation where you want to have multiple files associated with a single publication.

Here’s a modified version of the script above that should do what you want. I also updated all the variable names to hopefully make it clearer what’s going on, and added your code to add keywords as tags.

tell application "BibDesk"
	set bdSelection to selection of document 1
	if length of bdSelection > 1 then
		display alert "Select a single publication to link to DT"
		set bdSourceItem to item 1 of bdSelection
		-- get the cite key and create a new DT group with the same name and a link back to the BD record
		set bdCiteKey to cite key of bdSourceItem as string
		set mdCitation to ""
		-- get keywords to convert to tags
		set kw to keywords of bdSourceItem as string
		set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}
		set theTags to text items of kw
		set AppleScript's text item delimiters to od
		-- get the markdown citation
		export document 1 using template "exportMarkdown" to clipboard for bdSourceItem
		set mdCitation to the clipboard
		tell application id "DNtp"
			set dtpdf to the selection
			if length of dtpdf = 0 or length of dtpdf > 1 then
				display alert "Select a single record to link in DT"
				-- create a new group, move the existing file there, and add all the metadata
				tell think window 1 to set myGroup to create location bdCiteKey
				move record dtpdf to myGroup
				add custom meta data bdCiteKey for "Cite Key" to myGroup
				add custom meta data "x-bdsk://" & bdCiteKey for "BibDesk URL" to myGroup
				-- add the markdown citation to the new group (as a file, as metadata, and as the group name)
				create record with {name:bdCiteKey & " Markdown reference", plain text:mdCitation, type:markdown} in myGroup
				add custom meta data mdCitation for "Reference" to myGroup
				set name of myGroup to mdCitation
				set tags of myGroup to theTags
				-- get the DT link to add to the BD record
				set theDntp_Link to reference URL of myGroup
			end if
		end tell
		-- get all the fields from the BD item
		set theFields to fields of bdSourceItem
		-- add them all to the new DT group
		repeat with aField in theFields
			set fieldName to name of aField
			set fieldValue to the value of aField
			tell application id "DNtp"
				add custom meta data fieldValue for fieldName to myGroup
			end tell
		end repeat
		-- add the DT link to BibDesk
		add theDntp_Link to bdSelection
	end if
end tell

Also - here’s the code to add the BD urls to DT (substitute bdSourceItem for i if you’re adding it to the second version):

		set bdURLs to linked URLs of i
		repeat with u in bdURLs
			tell application id "DNtp"
				create record with {URL:u, type:bookmark} in myGroup
			end tell
		end repeat

Why do you ask that, Jim?

Just thinking. Do you have an answer? :blush:

I don’t understand the question :stuck_out_tongue:

Haha! :smiley:

Do you have a complete CSV from, exported from BibDesk, to process or is this discussion now all about interacting with BibDesk directly?

The Zotero thread and the slow execution speed of AppleScript have led me to think that the approach I took above may be overkill – see (DT3 Bibliography) Formatted reference from Custom MD for an alternative approach: one html file per pub. in BD, customisable like any BD template.

I completely forgot about this topic, Jim @BLUEFROG. My apologies.
I am bypassing the export csv part and simply using a script to copy the data from bib desk and pasting it into DT3.

I had started experimenting with a script that @cgrunenberg had posted somewhere (which I can’t seem to find) that was for importing a csv and taking the data from it into a DT3 record, but I was pulled back to my obligations and couldn’t finish it.

No worries. Life happens and we’re all very busy these days. :slight_smile:

Hi everyone!
I am a coming back user of DevonThink. In the past I used DT2 but I stopped using it because some things that were very important to were missing.

One of those things was BibDesk integration. BibDesk support is very important in my opinion because it is widely used in the Academic world since it is free; it is actively maintained and has two very distinct characteristics. The first one is that once a PDF is added to BibDesk, the app can find it even if the document is moved in the Finder. Files are stored using Mac OS aliases, so you can move them in the Finder without breaking BibDesk’s links. The second one, is that it can read comments/notes written in metadata. Programs like Skim, do their highlights in the file metadata and only BibDesk is able to read it.

DevonThink is very good at managing searches and PDFs. It seems that version 3 is even better and I am deeply considering coming back. It seems that if I Index a folder inside DT; moving PDFs inside DT do not cause troubles to BibDesk; BibDesk can find them anyway. This is a very big plus for using DT to sort PDFs for example.

I do not understand however, why BibDesk integration is so difficult or not standard in DT. I have tried this AppleScript and I have not been able to make it work.

BibDesk does not use a database, it seems just a simple .bib file with some special Base64tags to store MacOS links. DT can read the .bib file and makes a very nice sheet out of it, but it seems it cannot show the MacOS links stored in them.

Can anyone help me to understand if I am missing something here? Am I doing something in the way it is not supposed to be done?

1 Like

could you be more specific as to what you need that is missing right now?

Hi Bernardo, thank you for your interest.

I have found that DT is very good to keep notes and help overall with research.

I would like to see:

  1. A preference on DT that allows change the default drag and drop from copy to replicate. So, I can have references rather than copying PDFs to the database. So far, I have to index a folder and then do replicate manually to add them to groups. I spent hours doing this. It would have been easier just to drag and drop and specify replicate rather than copy. I could not create a shortcut either, it was only right click and replicate…
  2. A preference to change the default PDF reader to Skim. Or a way to tell the PDF reader to save in metadata rather than embedded by default. In some PDF documents this is a big problem since you cannot edit them reliably. I have lost the default cover of some books when I highlighted them. Other documents are copy protected.
  3. Import from BibDesk and read the MacOS aliases so I do not have to relink everything single PDF again manually. Maybe an option to store the PDFs inside DT or leave them where they are for compatibility.
  4. A way to export a PDF to BibDesk; so BibDesk can solve the reference details. This would be just an empty entry with the Mac alias, for example.
  5. A way to synchronise groups from BibDesk to DT and vice-versa.
  6. Many places have the option to download a BibDesk already, I would like to add that file to DT and a way to tell DT that this BibDesk file is from a particular PDF. At this point I have to be very careful not to mess everything.
  7. When I do searches in DT, it never tells me how many documents has found. This is so annoying.
  8. A pane to store my searches that I could modify later. The small Pop up menu is very limiting.

1. Inside DEVONthink, Command-Option-drag already does this. The default is to move, not copy.

2. You cannot change applications in DEVONthink. If it’s the system default application for PDFs, you can enable Preferences > General > Double-click opens documenrs externally.

3. through 5. could potentially be accomplished via scripting but there are no current plans for any direct integration with BibDesk.

7. DEVONthink absolutely does report the number of found items.

8. What small popup ?

Hi Bluefrog,

  1. I think you are talking inside DevonThink. I want to drag from the Finder into DT and it copies.

  2. I know about this option, but changing the default for everything is not what I would like. Skim is very good for taking annotations, but it is not as fast as Preview to just browse documents.

  3. to 5. Too bad there are no plans to do this.

7.Hi! You are right, I can see that I missed where items are found.

In DT2 there was an option to have a new window for searches. What I see know is that if I hit save the search, I just see in on the small triangle/magnifier glass next to the Search field. It is a small pop up menu. I cannot edit it or modify what I put there. Just clear searches.

You can’t replicate from the Finder into DEVONthink.
Command-drag from the Finder will move files into a database.
Command-Option-drag* from the Finder will index files.

You can use Data > Open With and choose a different application registered for the particular file type.

The Save button is shown in the at the right side of the scope bar above the results…

Note the smart group will be local if your scope is inside a database, but global if your scope is Databases or Inboxes