Skip to content

Instantly share code, notes, and snippets.

@bcdavasconcelos
Last active January 6, 2020 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcdavasconcelos/11428fc6a3f6e2c3f38aea22b9576217 to your computer and use it in GitHub Desktop.
Save bcdavasconcelos/11428fc6a3f6e2c3f38aea22b9576217 to your computer and use it in GitHub Desktop.
Script to link Bibdesk entries to DEVONthink Pro records along with custom metadata #Bibdesk #DEVONthink3 #Applescript
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
-- Script to link Bibdesk entries to DEVONthink Pro records along with custom metadata - by Bernardo Vasconcelos (July 2019).
-- This script is based on Kyle Eggletons script for Bookends and DEVONthink, April 2019.
-- Use at your own risk
tell application "BibDesk"
set theSelection to the selection of document 1
repeat with thisItem in theSelection
-- accessing field values
set theID to id of thisItem
set theCitation to cite key of thisItem
--set thePriority to the rating of thisItem as text
set theType to the type of thisItem as text
set theRating to the value of field "rating" of thisItem as text
set theTitle to the value of field "Title" of thisItem
set theAuthor to the name of author of field "Author" of item 1 of theSelection as text
set theAbstract to the value of field "abstract" of thisItem
set theEditor to the value of field "editor" of thisItem
set theTranslator to the value of field "Translator" of thisItem
set thePlace to the value of field "Address" of thisItem
set thePublisher to the value of field "publisher" of thisItem
set theYear to the value of field "Year" of thisItem
set theISBN to the value of field "isbn" of thisItem
set theJournal to the value of field "journal" of thisItem
set theVolume to the value of field "volume" of thisItem
set theIssue to the value of field "volume" of thisItem
set thePages to the value of field "pages" of thisItem
set theDOI to the value of field "doi" of thisItem
set theNotes to the value of field "Annote" of thisItem
set theKeywords to the value of field "keywords" of thisItem
set theLanguage to the value of field "language" of thisItem
set theAttachments to the value of field "attachments" of thisItem
set theURL to the linked URL of thisItem
try
set refVolume to ""
if theVolume is not "" then
set refVolume to " (" & the_volume & ")"
end if
end try
try
set refTranslator to ""
if theTranslator is not "" then
set refTranslator to "Trad.: " & theTranslator & ". "
end if
end try
try
set refEditor to ""
if theEditor is not "" then
set refEditor to "Ed.: " & theEditor & ". "
end if
end try
try
set refArticle to ""
set refArticle to (theAuthor & ". " & theTitle & ". In: " & theJournal & " " & refVolume & theIssue & ", " & theYear & "." & " Pp." & thePages)
end try
try
set refBook to ""
set refBook to (theAuthor & "; " & theTitle & ". " & refEditor & refTranslator & thePlace & ": " & thePublisher & ", " & theYear)
end try
try
set theRef to ""
if (theType = "article") then
set theRef to refArticle
else if (theType = "book") then
set theRef to refBook
end if
end try
end repeat
tell application id "DNtp"
try
set theRecord to the content record of think window 1
if theRecord is {} then error "Please select some contents."
end try
try
set thePriority to ""
if theRating is "1" then set thePriority to "1️⃣"
if theRating is "2" then set thePriority to "2️⃣"
if theRating is "3" then set thePriority to "🔥"
if theRating is "4" then set thePriority to "🔥🔥"
if theRating is "5" then set thePriority to "🔥🔥🔥"
end try
try
add custom meta data theCitation for "bibkey" to theRecord
add custom meta data thePriority for "Priority" to theRecord
add custom meta data theRating for "rating" to theRecord
add custom meta data theType for "type" to theRecord
add custom meta data theTitle for "title" to theRecord
add custom meta data theAbstract for "abstract" to theRecord
add custom meta data theAuthor for "authors" to theRecord
add custom meta data theEditor for "editor" to theRecord
add custom meta data theTranslator for "translator" to theRecord
add custom meta data thePlace for "Place" to theRecord
add custom meta data thePublisher for "publisher" to theRecord
add custom meta data theYear for "date" to theRecord
add custom meta data theISBN for "is?n" to theRecord
add custom meta data theJournal for "journal" to theRecord
add custom meta data theVolume for "volume" to theRecord
add custom meta data theIssue for "issue" to theRecord
add custom meta data thePages for "page" to theRecord
add custom meta data theDOI for "doi" to theRecord
add custom meta data theRef for "Reference" to theRecord
add custom meta data theNotes for "notas" to theRecord
add custom meta data theKeywords for "keywords" to theRecord
add custom meta data theLanguage for "language" to theRecord
add custom meta data ("x-bdsk://" & theCitation) for "bibdeskurl" to theRecord
add custom meta data theURL for "link2" to theRecord
--set the URL of theRecord to ("x-bdsk://" & theCitation) as text
end try
try
set the aliases of theRecord to theCitation
set the tags of theRecord to theKeywords
set the name of theRecord to theRef
set theDntp_Link to ""
set theDntp_Link to reference URL of theRecord
end try
end tell
end tell
tell application "BibDesk"
set theSelection to the selection of document 1
set the value of field "Local-url" of thisItem to theDntp_Link
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment