Skip to content

Instantly share code, notes, and snippets.

@bcdavasconcelos
Last active March 17, 2020 21:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcdavasconcelos/e52d93c6aa96012c356363644845549e to your computer and use it in GitHub Desktop.
Save bcdavasconcelos/e52d93c6aa96012c356363644845549e to your computer and use it in GitHub Desktop.
Add ABNT Reference Smart Rule for DT3 #DEVONthink3 #Applescript
on performSmartRule(theRecords)
tell application id "DNtp"
try
set these_items to the selection
if these_items is {} then error "Please select some contents."
repeat with this_item in these_items
set customMD to custom meta data of this_item
try
set the_type to mdtype of customMD
on error
set the_type to ""
end try
try
set the_authors to mdauthors of customMD
on error
set the_author to ""
end try
try
set the_editor to mdeditor of customMD
on error
set the_editor to ""
end try
try
set the_translator to mdtranslator of customMD
on error
set the_translator to ""
end try
try
set the_title to mdtitle of customMD
on error
set the_title to ""
end try
try
set the_publisher to mdpublisher of customMD
on error
set the_publisher to ""
end try
try
set the_date to mddate of customMD
on error
set the_date to ""
end try
try
set the_link2 to mdlink2 of customMD
on error
set the_link2 to ""
end try
try
set the_page to mdpage of customMD
on error
set the_page to ""
end try
try
set the_abstract to mdabstract of customMD
on error
set the_abstract to ""
end try
try
set the_bibkey to mdbibkey of customMD
on error
set the_bibkey to ""
end try
try
set the_doi to mddoi of customMD
on error
set the_doi to ""
end try
try
set the_sertitle to mdsertitle of customMD
on error
set the_sertitle to ""
end try
try
set the_journal to mdjournal of customMD
on error
set the_journal to ""
end try
try
set the_issue to mdissue of customMD
on error
set the_issue to ""
end try
try
set the_reference to mdreference of customMD
on error
set the_reference to ""
end try
try
set the_keywords to mdkeywords of customMD
on error
set the_keywords to ""
end try
try
set the_volume to mdvolume of customMD
on error
set the_volume to ""
end try
try
set the_place to mdplace of customMD
on error
set the_place to ""
end try
-- Article --
--try
-- set ref_doi to ""
--end try
--
--if the_doi is not "" then
-- try
-- set ref_doi to "<http://dx.doi.org/" & the_doi & ">"
-- end try
--end if
--
try -- in case volume is present
set ref_volume to ""
end try
if the_volume is not "" then
try
set ref_volume to " (" & the_volume & ")"
end try
end if
try
set ref_article to the_authors & "; " & the_title & ". In: " & the_journal & " " & ref_volume & the_issue & ", " & the_date & "." & " Pp." & the_page
end try
-- Book --
-- translator and editor --
try
set ref_translator to ""
set ref_editor to ""
end try
if the_translator is not "" then
try
set ref_translator to "Trad.: " & the_translator & ". "
end try
end if
if the_editor is not "" then
try
set ref_editor to "Ed.: " & the_editor & ". "
end try
end if
try -- the book ref
set ref_book to the_authors & "; " & the_title & ". " & ref_editor & ref_translator & the_place & ": " & the_publisher & ", " & the_date
end try
-- the reference --
if the_type is "Article" then
set the_ref to ref_article
end if
if the_type is "Book" then
set the_ref to ref_book
end if
add custom meta data the_ref for "reference" to this_item
try
set name of this_item to the_ref as text
end try
try
set the aliases of this_item to the_bibkey
end try
if the_keywords is not "" then
set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}
set theTags to text items of the_keywords
set AppleScript's text item delimiters to od
set theTags to (parents of this_item) & theTags
set the tags of this_item to theTags
set the mdkeywords of customMD to ""
end if
end repeat
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
end try
end tell
end performSmartRule
@bcdavasconcelos
Copy link
Author

bcdavasconcelos commented Jul 12, 2019

For more information, see this thread on DT3 Forum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment