Last active
December 20, 2015 23:39
-
-
Save fractaledmind/6213978 to your computer and use it in GitHub Desktop.
This script inserts a Markdown Inline Link for a DEVONthink item into your current TextMate (or TextEdit) document. You can choose either whatever item is currently selected, or you can navigate your DEVONthink database to insert a URL for any item.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
display dialog "Get Link of selected item or choose other item?" buttons {"Get Selected", "Choose Other"} default button {"Get Selected"} | |
--Get Markdown formatted info for selected item | |
if result = {button returned:"Get Selected"} then | |
tell application id "com.devon-technologies.thinkpro2" | |
set devon_selection to the selection | |
if devon_selection is {} then display dialog "Please select something." | |
set Markdown_link to "" | |
repeat with i from 1 to the count of devon_selection | |
set RecordLink to the reference URL of item i of devon_selection | |
set DevonThinkLink to RecordLink & "?page=0" | |
set PdfName to the name of item i of devon_selection | |
set theWikiLink to "[" & PdfName & "]" & "(" & DevonThinkLink & ")" | |
set Markdown_link to (Markdown_link) & theWikiLink | |
end repeat | |
end tell | |
--Export to TextMate | |
tell application "TextMate" | |
insert (theWikiLink) | |
end tell | |
(* If you don't have TextMate, here's the script for the universal Mac program TextEdit. To alter the code, merely delete or comment-out the TextMate tellblock and uncomment this block: | |
*) | |
-- tell application "TextEdit" | |
-- activate | |
-- make new word at end of text of document 1 with data theWikiLink | |
-- end tell | |
--Get Markdown formatted info for any item | |
else if result = {button returned:"Choose Other"} then | |
tell application id "com.devon-technologies.thinkpro2" | |
set theDB to database "Penn Graduate School" | |
set SelGroup to display group selector | |
set theGroup to item 1 of SelGroup | |
set allChildren to every child of theGroup | |
set listofChildren to {} | |
set listofLinks to {} | |
repeat with currentRecord in allChildren | |
set currentName to name of currentRecord | |
copy currentName to the end of listofChildren | |
set currentLink to reference URL of currentRecord | |
set DevonThinkLink to currentLink & "?page=0" | |
copy DevonThinkLink to the end of listofLinks | |
end repeat | |
set SelChild to choose from list of listofChildren with title "Select DEVONthink Item" with prompt "Current DEVONthink Items" OK button name "OK" | |
set devon_Child to SelChild as string | |
set notePlacement to my findAll(listofChildren, devon_Child) as number | |
set noteURL to item notePlacement of listofLinks | |
set theWikiLink to "[" & devon_Child & "]" & "(" & noteURL & ")" | |
end tell | |
--Export to TextMate | |
tell application "TextMate" | |
insert (theWikiLink) | |
end tell | |
(* If you don't have TextMate, here's the script for the universal Mac program TextEdit. To alter the code, merely delete or comment-out the TextMate tellblock and uncomment this block: | |
*) | |
-- tell application "TextEdit" | |
-- activate | |
-- make new word at end of text of document 1 with data theWikiLink | |
-- end tell | |
end if | |
(* SUBROUTINES *) | |
on findAll(lst, val) | |
-- HAS (http://applemods.sourceforge.net/mods/Data/List.php) | |
local lst, val, res | |
try | |
if lst's class is not list then error "not a list." number -1704 | |
if {val} is not in lst then return {} | |
set res to {} | |
script k | |
property l : lst | |
end script | |
repeat with i from 1 to count of k's l | |
if k's l's item i is val then set res's end to i | |
end repeat | |
return res | |
on error eMsg number eNum | |
error "Can't find All: " & eMsg number eNum | |
end try | |
end findAll |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment