Created
August 12, 2013 19:16
-
-
Save fractaledmind/6214128 to your computer and use it in GitHub Desktop.
This script can be compiled as an application to allow you to insert a Markdown Inline Link to either an Evernote, BibDesk, DEVONthink, or VoodooPad item into your current TextMate document. This script is central to my Wikify project, wherein I am attempting to interconnect as much of my desktop data as possible. Since these 4 apps all have cus…
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
| chooseLinkType({"Evernote", "DEVONthink", "BibDesk", "Voodoopad"}) | |
| on chooseLinkType(LinkList) | |
| set theResult to choose from list LinkList with title "Markdown Link Generator" with prompt "Link type:" OK button name "Select" cancel button name "None" default items {"Evernote"} | |
| if theResult is false then return 0 | |
| set refTypeNumber to theResult as string | |
| (* EVERNOTE *) | |
| if refTypeNumber is "Evernote" then | |
| display dialog "Get Link of selected note or choose other note?" buttons {"Get Selected", "Choose Other"} default button {"Get Selected"} | |
| --Get Markdown formatted info from Selected Note | |
| if result = {button returned:"Get Selected"} then | |
| tell application "Evernote" | |
| set Evernote_Selection to selection | |
| if Evernote_Selection is {} then display dialog "Please select a note." | |
| set noteLink to "" | |
| repeat with i from 1 to the count of Evernote_Selection | |
| set noteURL to note link of item i of Evernote_Selection | |
| set noteName to title of item i of Evernote_Selection | |
| set theWikiLink to "[" & noteName & "]" & "(" & noteURL & ")" | |
| set noteLink to (noteLink) & theWikiLink | |
| end repeat | |
| end tell | |
| --Export to TextMate | |
| tell application "TextMate" | |
| insert (noteLink) | |
| end tell | |
| --Get Markdown formatted info for any note | |
| else if result = {button returned:"Choose Other"} then | |
| tell application "Evernote" | |
| activate | |
| set listOfNotebooks to {} | |
| set EVNotebooks to every notebook | |
| repeat with currentNotebook in EVNotebooks | |
| set currentNotebookName to (the name of currentNotebook) | |
| copy currentNotebookName to the end of listOfNotebooks | |
| end repeat | |
| set Folders_sorted to my simple_sort(listOfNotebooks) | |
| set SelNotebook to choose from list of Folders_sorted with title "Select Evernote Notebook" with prompt ¬ | |
| "Current Evernote Notebooks" OK button name "OK" | |
| set EVnotebook to item 1 of SelNotebook | |
| set listofNotes to {} | |
| set listofLinks to {} | |
| set allNotes to every note in notebook EVnotebook | |
| repeat with currentNote in allNotes | |
| set currentNoteName to (the title of currentNote) | |
| copy currentNoteName to the end of listofNotes | |
| set currentNoteURL to (the note link of currentNote) | |
| copy currentNoteURL to the end of listofLinks | |
| end repeat | |
| set SelNote to ¬ | |
| choose from list of listofNotes with title ¬ | |
| "List of Notes" OK button name "Get Link" cancel button name "Close Window" | |
| set noteName to SelNote as string | |
| set notePlacement to my findAll(listofNotes, noteName) as number | |
| set noteURL to item notePlacement of listofLinks | |
| set theWikiLink to "[" & noteName & "]" & "(" & noteURL & ")" | |
| end tell | |
| --Export to TextMate | |
| tell application "TextMate" | |
| insert (theWikiLink) | |
| end tell | |
| end if | |
| (* DEVONTHINK *) | |
| else if refTypeNumber is "DEVONthink" then | |
| 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 | |
| --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 | |
| end if | |
| (* BIBDESK *) | |
| else if refTypeNumber is "BibDesk" then | |
| 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 "BibDesk" | |
| set bibdesk_selection to selection of first document | |
| if bibdesk_selection is "" then display dialog "Please select an item." | |
| set Markdown_link to "" | |
| repeat with i from 1 to the count of bibdesk_selection | |
| set CiteKey to cite key of item i of bibdesk_selection | |
| set ItemURL to "x-bdsk://" & CiteKey | |
| set itemName to title of item i of bibdesk_selection | |
| set theWikiLink to "[" & itemName & "]" & "(" & ItemURL & ")" | |
| set Markdown_link to (Markdown_link) & theWikiLink | |
| end repeat | |
| end tell | |
| --Export to TextMate | |
| tell application "TextMate" | |
| insert (Markdown_link) | |
| end tell | |
| else if result = {button returned:"Choose Other"} then | |
| tell application "BibDesk" | |
| set allDocs to every document of application "BibDesk" | |
| set listofDocs to {} | |
| repeat with theDoc in allDocs | |
| set thename to the name of theDoc | |
| copy thename to the end of listofDocs | |
| end repeat | |
| if (not ((count of listofDocs) is 1)) then | |
| set SelDoc to choose from list of listofDocs with title "Select BibDesk Database" with prompt ¬ | |
| "Current BibDesk Databases" OK button name "OK" | |
| set theDoc to item 1 of SelDoc | |
| else | |
| set theDoc to document 1 of application "BibDesk" | |
| end if | |
| set allGroups to every static group of theDoc | |
| set listofGroups to {} | |
| repeat with theGroup in allGroups | |
| set thename to the name of theGroup | |
| copy thename to the end of listofGroups | |
| end repeat | |
| set SelGroup to choose from list of listofGroups with title "Select BibDesk Group" with prompt ¬ | |
| "Current BibDesk Groups" OK button name "OK" | |
| set theGroup to item 1 of SelGroup | |
| set allPubs to every publication of group theGroup of theDoc | |
| set listofPubs to {} | |
| set listofLinks to {} | |
| repeat with thePub in allPubs | |
| set PubName to title of thePub | |
| copy PubName to the end of listofPubs | |
| set CiteKey to cite key of thePub | |
| set PubURl to "x-bdsk://" & CiteKey | |
| copy PubURl to the end of listofLinks | |
| end repeat | |
| set SelPub to choose from list of listofPubs with title "Select BibDesk Publication" with prompt ¬ | |
| "Current BibDesk Publications" OK button name "OK" | |
| set thePub to SelPub as string | |
| set PubPlacement to my findAll(listofPubs, thePub) as number | |
| set PubURl to item PubPlacement of listofLinks | |
| set theWikiLink to "[" & thePub & "]" & "(" & PubURl & ")" | |
| end tell | |
| --Export to TextMate | |
| tell application "TextMate" | |
| insert (theWikiLink) | |
| end tell | |
| end if | |
| (* VOODOOPAD *) | |
| else if refTypeNumber is "Voodoopad" then | |
| display dialog "Get Link of open page or choose other page?" 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 "VoodooPad" | |
| set voodoo_selection to the (current page name) as string | |
| if voodoo_selection is {} then display dialog "Please select something." | |
| set Markdown_link to "" | |
| set voodooID to uuid of page voodoo_selection of document 1 | |
| set ItemURL to "x-voodoopad-item://" & voodooID | |
| set theWikiLink to "[" & voodoo_selection & "]" & "(" & ItemURL & ")" | |
| set Markdown_link to (Markdown_link) & theWikiLink | |
| end tell | |
| tell application "TextMate" | |
| insert (Markdown_link) | |
| end tell | |
| else if result = {button returned:"Choose Other"} then | |
| tell application "VoodooPad" | |
| set vp_docs to get name of every document of application "VoodooPad" | |
| set SelDoc to choose from list of vp_docs with title "Select Voodoopad Document" with prompt ¬ | |
| "Current Voodoopad Documents" OK button name "OK" | |
| set theDoc to item 1 of SelDoc | |
| set allPages to get name of every page of document theDoc | |
| set SelPage to choose from list of allPages with title "Select Voodoopad Page" with prompt ¬ | |
| "Current Voodoopad Pages" OK button name "OK" | |
| set thePage to item 1 of SelPage | |
| set Markdown_link to "" | |
| set voodooID to uuid of page thePage of document theDoc | |
| set ItemURL to "x-voodoopad-item://" & voodooID | |
| set theWikiLink to "[" & thePage & "]" & "(" & ItemURL & ")" | |
| set Markdown_link to (Markdown_link) & theWikiLink | |
| end tell | |
| tell application "TextMate" | |
| insert (Markdown_link) | |
| end tell | |
| end if | |
| end if | |
| end chooseLinkType | |
| (* SUBROUTINES *) | |
| on simple_sort(my_list) | |
| set the index_list to {} | |
| set the sorted_list to {} | |
| repeat (the number of items in my_list) times | |
| set the low_item to "" | |
| repeat with i from 1 to (number of items in my_list) | |
| if i is not in the index_list then | |
| set this_item to item i of my_list as text | |
| if the low_item is "" then | |
| set the low_item to this_item | |
| set the low_item_index to i | |
| else if this_item comes before the low_item then | |
| set the low_item to this_item | |
| set the low_item_index to i | |
| end if | |
| end if | |
| end repeat | |
| set the end of sorted_list to the low_item | |
| set the end of the index_list to the low_item_index | |
| end repeat | |
| return the sorted_list | |
| end simple_sort | |
| 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