Hackademic 8 Posted June 4, 2013 Share Posted June 4, 2013 Like many users (I imagine), I initially fell in love with Evernote and its ability truly to be my external brain. I have used it extensively this year (my first year of grad school). However, I began to flirt with alternatives in the wiki-verse because I really love the idea of what I call organic horizontal organization; that is, a form of organization at the base level of notes (or pages, or documents, or what ever you call your base note form) that is interconnected among itself, creating an inter-locking, inter-linking web. This is the true power of wikis. As a Mac user, I worked with Voodoopad for a while. Although I loved to no hassle page linking (simply type a WikiWord and a new page is created; if a page exists and you type its title somewhere, it is automatically linked), I did not love the Interface. Specifically, I felt it greatly lacked a means of powerful Vertical Organization; that is, the nested organization with multiple levels seen in Finder, for example. This was always one of my favorite aspects of EN as well, with the Stacks and Notebooks. Another issue for the personal desktop wiki program was the cumbersomeness of external linking. While it was almost magical how easily Voodoopad linked to voodoopad pages, it was quite the hassle to link to external files. I was particularly frustrated by this fault because I take advantage of numerous apps now creating their own custom URL schemes to create an inter-linked knowledge base across my various applications. In struggling to automate external link creation in Voodoopad via Applescript, I stumbled across Markdown (I'm late to the game, I know). While I had seen simply Markdown syntax before (# for header, etc), I had not seen the Markdown linking syntax. It is quite simple, and being plain text, easily automated. Unfortunately, while Voodoopad can export its documents from Markdown to HTML, it cannot easily view Markdown as HTML within the program. Thus my cross-app links look quite ugly (i.e. The script below will take the text of an EN note, search for WikiWords, and create new notes with those WikiWord titles. It will then retrieve the note links of these new notes, create Markdown formated [title](link) entries for each, and replace them in the text. One then merely pastes into Markable and exports to EN. With this script, you can write a new note, put in WikiWords as you wood in a personal wiki and it will generate new pages if necessary and link to all pages with WikiWord titles. The script currently creates all new notes in a new Notebook that is named the original note title. Each note you write thus becomes an Index Page (in Voodoopad speak) for its sub notes. While the script doesn't quite create the fluidity of a personal desktop wiki (finishing typing a word and it links), it does create a very fluid wiki-like experience in EN (tests run appr. 3 seconds). This script is definently a beta. And I am an Applescript noob, so I doubt it is the most efficient. But it works quick enough for me. Any additions or alterations are welcome. I would love to add soon an AutoLinking function (a la Voodoopad's automatically link to a page if you type the page title), as well as migrate away from the third-party app Markable to get from Markdown to Evernote. But, as it stands, this script will Wikify your Evernote. Script is here (the forum won't currently let me attach a script file to the post, sorry). (* Wikify Evernote Applescript-- Stephen Margheim-- open sourcethis script take the selected note and treat it as the Index Page for Wiki-Style sub-pages created in a seperate Notebook that is entitled the same as your Note. It uses WikiWords and [bracketed] words as the base for the newly created notes. NOTE: You may either type WikiWords or [bracketed] words, but multiple words within brackets (i.e. [multiple words]) will create 2 notes: "multiple" and "words". The script functions by [1] turning the content of the selected EN note into plain text, [2] searching that text for WikiWords and placing [brackets] around them, [3] extracting all terms that are contained within [brackets], [4] creating a new Notebook in EN (if necessary) with name of selected note, [5] searching EN for existing notes with titles of the [bracketed] terms, a "Wiki" tag, and placed in the newly created Notebook, [6] creating all necessary notes in the new Notebook, [7] getting the note links of all the notes in that new Notebook, [8] putting the note name and note URl together in Markdown format, [9] putting [brackets] back around the note titles, [10] creates 2 lists: one, of [bracketed] note titles (which were WikiWords and [brackets] in original note); and two, of Markdown formatted note titles and note links, [11] removes any duplicates from lists, [12] sorts both lists so that they are in the same order, [13] finds [bracketed] terms and WikiWords in original notes and replaces with Markdown formatted [Note Title](Note Link), and finally [14] exports new text to Markdown editor for Evernote, Markable. At this point the user must manually export the Markdown text to Evernote as HTML (very important, and not currently the default setting). Currently, exporting to EN opens dialog box with Notebooks--navigate to notebook with original note--and then to the notes in that Notebook--navigate to the original note--and update. A bug in the current version of Markable renames the orifinal EN to "Unsaved" if the Markable document is not saved in the program. I have seen Ruby scripts online to push Markdown to EN, but have yet to explore how best to integrate them into this script. I am sure it is easy, and would get rid of the manual export in Markable (as well as the current bugs). So if anyone wants to embed those Ruby scripts, feel free. I would love that. I note upfront that this is cobbled together from numerous other scripts and handlers; some altered more than others. I have attempted to note original authors for sections of the script throughout, but I haven't slept much, so I'm not certain that I didn't miss a few. *) --get selected notetell application "Evernote"tryset Evernote_Selection to selectionif Evernote_Selection = {} thendisplay dialog "Please select the note to Wikify"end ifset noteName to (title of item 1 of Evernote_Selection)end try --get plain text of note; from Justin's Veritrope scriptset the_HTML to HTML content of (item 1 of Evernote_Selection)set plain_Text to do shell script "echo " & quoted form of the_HTML & space & "| textutil -convert txt -stdin -stdout" end tellset the clipboard to plain_Text Wikify() set Bracketed_text to the clipboard tell application "Evernote"set Evernote_text to the clipboardend tell extractBetween(Evernote_text, "[", "]") set Bracket_list to the clipboardset BracketLater_list to get words of Bracket_list --search for and create notes from above listtell application "Evernote"set tid to AppleScript's text item delimitersset Wiki_list to the clipboardset Wiki_list_count to (count words of Wiki_list) as numberif (not (notebook named noteName exists)) thenmake notebook with properties {name:noteName}end ifset notebook1 to notebook noteNameset notebook_search to name of notebook1set i to 1repeat with i from 1 to Wiki_list_countset Wiki_word to word i of Wiki_listset matches to find notes "intitle:" & Wiki_word & " " & "tag:Wiki" & " " & "notebook:\"" & notebook_search & "\"" if matches = {} thenset Wiki_note to create note title Wiki_word with text "" notebook notebook1if (not (tag named "Wiki" exists)) thenmake tag with properties {name:"Wiki"}end ifset tag1 to tag "Wiki"assign tag1 to Wiki_noteend ifif (i > Wiki_list_count) thenexit repeatend ifend repeat --All sub notes are now created with appropriate tag and title--Next, synchronize to get note links for all wiki notes set noteLink to missing valuerepeat until isSynchronizing is falseend repeatsynchronize delay 0.1 end tell delay 1--to ensure that the sync is complete before querying for note links (have had "missing value" returned with smaller delay. If you have a larger note, you may need to up the delay here to get all your note link data below --get note links for all wiki notestell application "Evernote"set theNotebook to notebook notebook_searchset Evernote_Selection to every note of theNotebook set wikiLinks to {}set the clipboard to "" repeat with i from 1 to the count of Evernote_Selectionset noteURL to note link of item i of Evernote_Selectionset noteName to title of item i of Evernote_Selectionset theWikiLink to "[" & noteName & "]" & "(" & noteURL & ")" & returnset the clipboard to (the clipboard) & theWikiLinkend repeatset WikiLinks_list to the clipboardend tell delay 0.5--another safety-valve to ensure EN is caught up with our quick data retrieval --put [brackets] back around the terms from the earlier list that created the new EN notes above; for find and replace laterset NewBracket_list to every item of BracketLater_listset the clipboard to "" repeat with i from 1 to the count of NewBracket_listset itemName to item i of NewBracket_listset theBracketName to "[" & itemName & "]" & returnset the clipboard to (the clipboard) & theBracketNameend repeat set NewBracket_list2 to the clipboard--this variable has a simple string of your WikiWords set Bracket_list2 to get paragraphs of NewBracket_list2--this variable puts bracketed text string into list form set WikiLinks_list2 to get paragraphs of WikiLinks_list--this variable takes your list of Wiki-Markdown links and puts into list form --delete any duplicate WikiWords in your note from the Listset this_text to Bracket_list2set FinalBracketList to my remove_duplicates(this_text) --sort both lists to get in indentical orderset Sorted_FinalBracketList to my simple_sort(FinalBracketList)set Sorted_WikiLinks_list2 to my simple_sort(WikiLinks_list2) --find and replace [bracketed] terms in the text with Markdown [title](link)set the_string to Bracketed_textset search_strings to Sorted_FinalBracketListset replace_strings to Sorted_WikiLinks_list2 set ListNumber to the (count of search_strings) as numberset OldDelims to AppleScript's text item delimitersset the clipboard to "" repeat with i from 1 to ListNumberset AppleScript's text item delimiters to item i of search_stringsset newText to text items of the_stringset AppleScript's text item delimiters to item i of replace_stringsset the_string to newText as textset the clipboard to the_string set AppleScript's text item delimiters to OldDelims end repeat set FinalText to the clipboard--this says it all! --Send Markdown text to Markabletell application "Markable"activateactivateend tell tell application "System Events"keystroke "a" using {command down}keystroke "v" using {command down}end tell (* Here, the user must manually export to EN. Note the Preview in Markable. Ensure text is sound. To export, go Export -> Save To Evernote. Dialog box opens with list of your Notebooks. At bottom is choice between "Format: Markdown [or] HTML". Markdown will be selected. Select HTML. Then select your Notebook, and navigate to the original note. Save and return to EN to sync. If title is renamed to "Unsaved", be sure to re-rename it to its original title. Hopefully, if someone else can fit this into the Ruby shell, these issues will likely dissolve by circumventing Markable*) (* SUBROUTINES *) --Wikify handler from Fridemar Pache on Wikify() considering caseset clb to the clipboard as textif clb = "" thenexit repeatend ifset UpperCaseChars to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"set LowerCaseChars to "abcdefghijklmnopqrstuvwxyz"set Digits to "0123456789"set WikiWordChars to UpperCaseChars & LowerCaseChars & Digitsset countClb to (count characters of clb)set i to 1set currentChar to character i of clbset wikifiedText to ""repeat while i ≤ countClb-- a substring before a wikiWordrepeat while i ≤ countClbset possibleWikiWord to ""set CamelCaseCount to 0if (currentChar is in UpperCaseChars) thenexit repeatend ifset wikifiedText to wikifiedText & currentCharset i to i + 1if (i > countClb) thenexit repeatend ifset currentChar to character i of clbend repeat-- possible WikiWordrepeat while (i ≤ countClb)set possibleWikiWord to possibleWikiWord & currentCharif currentChar is in UpperCaseChars thenset CamelCaseCount to CamelCaseCount + 1end ifset i to i + 1if (i > countClb) thenexit repeatend ifset currentChar to character i of clbif not (currentChar is in WikiWordChars) thenif CamelCaseCount ≥ 2 thenset WikiWord to possibleWikiWordset wikifiedText to wikifiedText & "[" & WikiWord & "]"exit repeatelseset noWikiWord to possibleWikiWordset wikifiedText to wikifiedText & noWikiWordexit repeatend ifend ifend repeatend repeatset the clipboard to wikifiedTextend consideringend Wikify --Search with brackets handler from Yvan Koenig to extractBetween(SearchText, startText, endText)set tid to AppleScript's text item delimitersset AppleScript's text item delimiters to startTextset liste to text items of SearchTextset AppleScript's text item delimiters to endTextset extracts to {}repeat with subText in listeif subText contains endText thencopy text item 1 of subText to end of extractsend ifend repeatset AppleScript's text item delimiters to " "set extracts to extracts as textset the clipboard to extractsset AppleScript's text item delimiters to tidend extractBetween --handler from Qwerty Denzel on MacScripteron remove_duplicates(this_text)set not_list to class of this_text is not listif not_list then set this_text to paragraphs of this_textset new_text to {}repeat with this_line in this_textif this_line is not in new_text then set end of new_text to (contents of this_line)end repeatif not_list thenset text item delimiters to returntell new_text to set new_text to beginning & ({""} & rest)set text item delimiters to ""end ifreturn new_textend remove_duplicates --from www.macosautomation.comon simple_sort(my_list)set the index_list to {}set the sorted_list to {}repeat (the number of items in my_list) timesset the low_item to ""repeat with i from 1 to (number of items in my_list)if i is not in the index_list thenset this_item to item i of my_list as textif the low_item is "" thenset the low_item to this_itemset the low_item_index to ielse if this_item comes before the low_item thenset the low_item to this_itemset the low_item_index to iend ifend ifend repeatset the end of sorted_list to the low_itemset the end of the index_list to the low_item_indexend repeatreturn the sorted_listend simple_sort Link to comment
Laurent Sarrazin 67 Posted June 4, 2013 Share Posted June 4, 2013 Thank you very much for sharing !I'll give it a try Laurent Link to comment
Level 5* GrumpyMonkey 4,314 Posted June 4, 2013 Level 5* Share Posted June 4, 2013 Like many users (I imagine), I initially fell in love with Evernote and its ability truly to be my external brain. I have used it extensively this year (my first year of grad school). However, I began to flirt with alternatives in the wiki-verse because I really love the idea of what I call organic horizontal organization; that is, a form of organization at the base level of notes (or pages, or documents, or what ever you call your base note form) that is interconnected among itself, creating an inter-locking, inter-linking web. This is the true power of wikis. As a Mac user, I worked with Voodoopad for a while. Although I loved to no hassle page linking (simply type a WikiWord and a new page is created; if a page exists and you type its title somewhere, it is automatically linked), I did not love the Interface. Specifically, I felt it greatly lacked a means of powerful Vertical Organization; that is, the nested organization with multiple levels seen in Finder, for example. This was always one of my favorite aspects of EN as well, with the Stacks and Notebooks. Another issue for the personal desktop wiki program was the cumbersomeness of external linking. While it was almost magical how easily Voodoopad linked to voodoopad pages, it was quite the hassle to link to external files. I was particularly frustrated by this fault because I take advantage of numerous apps now creating their own custom URL schemes to create an inter-linked knowledge base across my various applications. In struggling to automate external link creation in Voodoopad via Applescript, I stumbled across Markdown (I'm late to the game, I know). While I had seen simply Markdown syntax before (# for header, etc), I had not seen the Markdown linking syntax. It is quite simple, and being plain text, easily automated. Unfortunately, while Voodoopad can export its documents from Markdown to HTML, it cannot easily view Markdown as HTML within the program. Thus my cross-app links look quite ugly (i.e. Thanks for the very interesting post, and for bringing up one of the missing features I wish Everntoe had: automatic linking to note titles. It is too bad we don't have it, but unlike VoodooPad, we also don't have unique titles, so it could get confusing if they tried to implement it! As for VoodooPad, you said it cannot easily view Markdown from within the app, but I think that is incorrect. If a page is in Markdown format (you have a choice of plain text, rich text, and markdown for your pages -- this can be changed in the default settings as well) then just press CMD Ctrl P to see it rendered in Markdown. It isn't as elegant as nvALT (a Notational Velocity fork) that goes from plain text to Markdown without needing to be in "Markdown" format, but it is easily done. It would be nice if Evernote had Markdown support. Will that be in your next script for us Link to comment
Hackademic 8 Posted June 4, 2013 Author Share Posted June 4, 2013 @GrumpyMonkey, I tried to get Voodoopad's HTML viewing to work for me, but because the program can only offer a preview of what the Markdown text would look like the links aren't functional except in that preview. To create a fuller wiki-feel with both internal and external links active, you have to create a Custom URL within a page or document. Tried as I might, I could never get Applescript to automate this process with numerous links, so Voodoopad ended up failing to offer me the functionality I wanted. I too was looking into automatic linking to note titles, for a fuller wiki-like experience. My first script will create all new notes with titles and link to the current note, but this merely turns any scripted note into an Index Page with a corresponding Notebook floating around with the sub-notes within it. This is an important function of a wiki (to auto-generate new spaces to take notes that correspond to the note and thoughts you are writing now), but it is far from the only or most important feature. When Voodoopad automatically recognized that the word I just typed corresponded to another already existing page, it felt magical. I wanted to try and recreate this function with a similar method as used in the script above. So this morning I wrote a new script. As you noted GrumpyMonkey, Evernote doesn't utilize unique titles, so as a workaround I utilize the "Wiki" tag. As you can see from my first script, all new sub-notes created are tagged with the "Wiki" tag. So as you create and broaden you interconnected Wiki notes, all of them will have this tag, regardless of where they are or what they are titled. This script will get a list of every note title for the notes with the "Wiki" tag. It then searches the text of the original note for any occurrences of these titles. Whatever hits it finds, it puts a Markdown formatted [title](link) in its place. You then export back to Evernote from Markable, and Voila! you have linked your note back to pre-existing wiki-notes. A few bugs: [1] I threw this together hastily, so it gathers it gathers all the titles of tag:Wiki notes and generates a full list Markdown [title](link) entries for each item. It then searches the original text for any occurrence of a title and replaces it with Markdown entry. However, as a result, as your list of tag:Wiki notes grows, this process slows. In testing, I ran into some strange lags while running and found delays helped. So you might have to increase delays as your library grows. Alternatively, I know that it would be possible to order to sequence better to [1] get titles, [2] search text for titles, [3] any matches -> get Markdown, [4] replace originals with Markdown. Hopefully, I will have time to alter this later. [2] As I said, I found some really strange lags in testing. The script would run continuously. I searched and searched for the issue, but as I ran each section separately, it worked easily. I put in delays and this appears to have fixed it. My only guess now is that moving back and forth from text manipulation to Evernote manipulation is tricky and requires delays to let all the variables return to stable modes. [3] If you have multiple notes with the same title within the "Wiki" tag (i.e. "WikiWords" note in notebook A and "WikiWords" note in notebook , it will only link to one of these notes. Once again, this is a beta and I welcome improvements and thoughts. I hope to continue to add wiki functionality to Evernote thru Applescript by writing a small script to interlink all tag:Wiki notes with the same titles, so that even tho you only link to one note within the current note, you still have access to all versions of that note title. Here is the script: --get the text content of the selected note tell application "Evernote" try set Evernote_Selection to selection if Evernote_Selection = {} then display dialog "Please select the note to Wikify" end if set noteName to (title of item 1 of Evernote_Selection) end try --get plain text of note; from Justin's Veritrope script set the_HTML to HTML content of (item 1 of Evernote_Selection) set plain_Text to do shell script "echo " & quoted form of the_HTML & space & "| textutil -convert txt -stdin -stdout" end tell delay 0.1 --search Evernote for all previously existing Wiki notes and get list of titles tell application "Evernote" set WikiSearch to find notes "tag:Wiki" set listofNotes to {} set allNotes to every item in WikiSearch repeat with currentNote in allNotes set currentNoteName to (the title of currentNote) copy currentNoteName to the end of listofNotes end repeat end tell delay 0.1 --put [brackets] around the search terms from the list of Wiki EN notes; for find and replace later set Bracket_list to every item of listofNotes set the clipboard to "" repeat with i from 1 to the count of Bracket_list set itemName to item i of Bracket_list set theBracketName to "[" & itemName & "]" & return set the clipboard to (the clipboard) & theBracketName end repeat set Bracketed_search_terms to the clipboard set FinalBracketed_list to get paragraphs of Bracketed_search_terms delay 0.1 --delete any duplicate WikiWords in your note from the List set NewBracket_list to my remove_duplicates(FinalBracketed_list) set Final_listofNotes to my remove_duplicates(listofNotes) delay 0.1 --put brackets around all instances of search terms in note set the_string to plain_Text set search_strings to Final_listofNotes set replace_strings to NewBracket_list set ListNumber to the (count of search_strings) as number set OldDelims to AppleScript's text item delimiters set the clipboard to "" repeat with i from 1 to ListNumber set AppleScript's text item delimiters to item i of search_strings set newText to text items of the_string set AppleScript's text item delimiters to item i of replace_strings set the_string to newText as text set the clipboard to the_string set AppleScript's text item delimiters to OldDelims end repeat set AlmostFinalText to the clipboard delay 0.1 --put list of Wiki notes into Markdown format with [title](link) tell application "Evernote" set noteLink to missing value repeat until isSynchronizing is false end repeat synchronize delay 5 set the clipboard to "" repeat with i from 1 to the count of listofNotes set search_string to item i of listofNotes set matches to find notes "intitle:" & search_string set noteURL to note link of item 1 of matches set noteName to title of item 1 of matches set theWikiLink to "[" & noteName & "]" & "(" & noteURL & ")" & return set the clipboard to (the clipboard) & theWikiLink set wikiLinks to the clipboard end repeat end tell delay 0.1 set WikiLinks_list to paragraphs of wikiLinks set newWikiList to my remove_duplicates(WikiLinks_list) delay 0.1 set EmptyItem to {""} set FinalBracket_list to my remove_emptyitem(NewBracket_list, EmptyItem) set FinalWiki_list to my remove_emptyitem(newWikiList, EmptyItem) delay 0.1 set Blist to FinalBracket_list as list set Wlist to FinalWiki_list as list set Atext to AlmostFinalText as text --find and replace [bracketed] terms in the text with Markdown [title](link) set the_string to Atext set search_strings to Blist set replace_strings to Wlist try set ListNumber to the (count of search_strings) as number set OldDelims to AppleScript's text item delimiters set the clipboard to "" repeat with i from 1 to ListNumber set AppleScript's text item delimiters to item i of search_strings set newText to text items of the_string set AppleScript's text item delimiters to item i of replace_strings set the_string to newText as text set the clipboard to the_string set AppleScript's text item delimiters to OldDelims end repeat end try --Send Markdown text to Markable. I use Fluid to make Markable a desktop app that can be called to activate. For the Paste below to work, Markable most be already open, with either a clean document or pre-existing text (tho this text will be deleted, so be forewarned) tell application "Markable" activate end tell --paste the clipboard into Markable and export to Evernote. (* SUBROUTINES *) --handler from Qwerty Denzel on MacScripter on remove_duplicates(this_text) set not_list to class of this_text is not list if not_list then set this_text to paragraphs of this_text set new_text to {} repeat with this_line in this_text if this_line is not in new_text then set end of new_text to (contents of this_line) end repeat if not_list then set text item delimiters to return tell new_text to set new_text to beginning & ({""} & rest) set text item delimiters to "" end if return new_text end remove_duplicates --edited from julifos' script on MacScripter on remove_emptyitem(start_list, remove_item) set theList to start_list set itemsToDelete to remove_item set prevTIDs to AppleScript's text item delimiters set AppleScript's text item delimiters to "TRICK" set theList to "TRICK" & theList & "TRICK" --> theList = "TRICKabTRICKbcTRICKcdTRICKdeTRICK" repeat with i in itemsToDelete set AppleScript's text item delimiters to "TRICK" & i & "TRICK" set theList to theList's text items set AppleScript's text item delimiters to "TRICK" set theList to theList as text end repeat set AppleScript's text item delimiters to "TRICK" --> (theList's text 6 thru -6) = "abTRICKcd" set theList to (theList's text 6 thru -6)'s text items set AppleScript's text item delimiters to prevTIDs return theList end remove_emptyitem Link to comment
Hackademic 8 Posted June 5, 2013 Author Share Posted June 5, 2013 For those interested, I have updated both scripts. Both scripts ought to be cleaner and more efficient now. As I noted above, my goal is to mimic the key functionality of personal wiki programs:[1] to autolink to new notes that are created without having to leave the current note[2] to autolink to pre-existing notes without having to leave the current note Each script performs one of these functions. In the future, I will try to combine them into one autolinking script. As I note in the preamble to both scripts, I have changed my method of getting the Mardown text into Evernote. Instead of using the online Markdown editor Markable.in, I installed the Markdown2Evernote command for TextMate. Unfortunately, this does not mean I can fully automate the process, as my keyboard shortcut doesn't work. But as soon as I figure that out, these scripts will require no manual work. The autolink to pre-existing notes also integrates the change I listed earlier, to get the note links only of the notes that have titles in the text. This keeps from bogging the script down once you have a large number of Wiki notes. Please experiment and try these out. I would love to get more feedback on how well they work. They work great on my machine, and I am now well on my way to creating a functioning wiki-style personal Evernote. I have attached both scripts below as .txt files. Wikify Evernote_autolinking to existing notes v.2.txtWikify Evernote_autolinking to new notes v.2.txt Link to comment
Hackademic 8 Posted June 6, 2013 Author Share Posted June 6, 2013 It would be nice if Evernote had Markdown support. Will that be in your next script for us I realized that this wouldn't be overly difficult to accomplish, especially given the existence of the Markdown2Evernote command for TextMate (which I have figured out how to automate, so that my codes are now fully automated with no user interaction required). Tim Lockridge gives a good explanation of how to install this command here (http://blog.timlockridge.com/blog/2013/02/03/using-textmate-and-markdown-with-evernote-configuring-a-workflow/). At the end of his post he notes, "Because Evernote doesn’t support plain text, there isn’t a way to convert the note back to Markdown. This is a one-way workflow." So I wrote an Applescript to make it a two-way workflow. Essentially, the script merely gets the appropriate note meta-data of the selected note, turns the content into plain text, pastes that plain text into TextMate with the appropriate preamble defined, exports that to Evernote, and then deletes the old notes. I tested the script to see how much Markdown syntax Evernote will recognize. I used the example text found here (http://www.markitdown.net/markdown) to generate this note (https://www.evernote.com/shard/s41/sh/4e18cf9f-b229-4a02-af80-9fed9e7ae94f/d3bd440a149a060ee7670159cfedc9ff). By looking at the preview from the webpage and the EN note, you can see the features EN doesn't translate. I will compile a list later. For now, enjoy a workflow to get Markdown text out of Evernote and then back in in HTML format. (* Markdown export for Evernote. -- Stephen Margheim -- open source VERSION 1.O This script enables the user to create notes within Evernote using Markdown syntax, whether in the iOS, Android, Windows, or Mac client, and run when on the Mac to generate HTML content notes. It uses the Markdown2Evernote command for the Markdown bundle of TextMate. Instructions for installation are here (http://blog.timlockridge.com/blog/2013/02/03/using-textmate-and-markdown-with-evernote-configuring-a-workflow/). As Tim notes in his post, that command is a one-way program. It sends Markdown written text in TextMate to Evernote. This is other half of that equation. It allows the user to get text from Evernote with Markdown syntax and send it back in HTML format. *) --get the text content of the selected note tell application "Evernote" try set Evernote_Selection to selection if Evernote_Selection = {} then display dialog "Please select a note" end if set noteName to (title of item 1 of Evernote_Selection) set notebookName to (name of notebook of item 1 of Evernote_Selection) set list_Tags to {} set names_Tags to "" set list_Tags to tags of (item 1 of Evernote_Selection) set count_Tags to count of list_Tags repeat with list_Tag in list_Tags set the_Name to name of list_Tag set names_Tags to (names_Tags & the_Name as string) if count_Tags is greater than 1 then set names_Tags to (names_Tags & ", " as string) set count_Tags to (count_Tags - 1) end if end repeat end try --get plain text of note; from Justin's Veritrope script set the_HTML to HTML content of (item 1 of Evernote_Selection) set plain_Text to do shell script "echo " & quoted form of the_HTML & space & "| textutil -convert txt -stdin -stdout" end tell set the clipboard to plain_Text --Send Markdown text to TextMate. TextMate must have a clean text document open. tell application "TextMate" activate insert "Title: " & noteName tell application "System Events" key code 52 end tell insert "Notebook: " & notebookName tell application "System Events" key code 52 end tell insert "Keywords: Markdown," & " " & names_Tags tell application "System Events" key code 52 key code 52 keystroke "v" using {command down} end tell delay 0.5 end tell --send Markdown formatted text to Evernote menu_click({"TextMate", "Bundles", "Markdown", "Markdown2Evernote"}) --delete old note tell application "Evernote" set FinalSearch to find notes "intitle:" & "\"" & noteName & "\"" & " " & "-tag:Markdown" delete FinalSearch end tell (* SUBROUTINES *) -- `menu_click`, by Jacob Rus, September 2006 on menu_click(mList) local appName, topMenu, r if mList's length < 3 then error "Menu list is not long enough" set {appName, topMenu} to (items 1 through 2 of mList) set r to (items 3 through (mList's length) of mList) tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬ (menu bar 1)'s (menu bar item topMenu)'s (menu topMenu))) end menu_click on menu_click_recurse(mList, parentObject) local f, r set f to item 1 of mList if mList's length > 1 then set r to (items 2 through (mList's length) of mList) tell application "System Events" if mList's length is 1 then click parentObject's menu item f else my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f))) end if end tell end menu_click_recurse Link to comment
Hackademic 8 Posted June 6, 2013 Author Share Posted June 6, 2013 I should explain further. This does not turn a regular note into Markdown. It allows a user to type up a note, say on their smartphone, using the Markdown syntax and to then convert that note to HTML and put it back in Evernote later, replacing the original. As promised, here is a list of what elements of Markdown Evernote translates properly. There are only two that Evernote doesn't translate:[1] # Header -> for whatever reason, Evernote deletes everything following a single # [2] Reference Links: [title][id] with later [id]: Otherwise, Evernote translates all of these syntaxes when using Markdown2Evernote:Supported:[1] *italics*[2] **bold**[3] ordered list[4] unordered list[5] ## second level header[6] ### third level header[7] `inline code`[8] > quote[9] [title](URL)[10] <URL>[11] --- Horizontal Rule Link to comment
g_b 0 Posted June 6, 2013 Share Posted June 6, 2013 sm@rgh, nice work I'll definitly give it a try! The workflow to create a markdown note in evernote by Brett Terpstra and Martin Kopischke uses the first '# headline' to get the name of the new note and ignores the rest of it http://nsuserview.kopischke.net/post/6223792409/i-can-has-some-markdown:"you can mix short syntax (i.e. “@” for tags, “=” for the notebook and “#” for the title ) and MMD syntax metadata lines freely, but both will only be parsed inside the MMD metadata block, so you don’t have to worry about random paragraphs starting with metadata keywords being stripped out of your text (note that if you provide multiple metadata lines in the block, only the last one will be kept). The one exception to this being atx style 1st level headings (i.e. # My heading), which are intrinsically outside the metadata block anyway and will be parsed anywhere; the first one becomes the title, the others are stripped from the Markdown." Setext-style headers will work fine header===== Link to comment
Hackademic 8 Posted June 6, 2013 Author Share Posted June 6, 2013 I am happy to say that I have successfully united my two scripts. You may now assign this script to an Automator Service that it contextually linked to Evernote, assign it a unique hotkey, and voila! you can efficiently Wikify your Evernote. Essentially, this new script searches your Evernote for pre-existing notes with the "Wiki" tag and places ((double parentheses)) around any terms or phrases in your text that match any of those notes. It get gathers the note link info, puts them into Markdown format, and finds and replaces the ((para)) terms with Markdown [title](link) terms. It then (tho not in exactly this order) searches for any WikiWords in the text. Any such words are [[double bracketed]] (thus, you may also put [[double brackets]] around a non-WikiWord term to create a new note). It then creates a new notebook with the original notes title, and creates new notes within that notebook with the titles of the WikiWords or [[bracketed terms]]. It get grabs the note link info for these new notes and puts the info in Markdown format. One more find and replace to get the [[bracketed]] terms out and the new [title](link) terms in. Finally, the script exports the text to TextMate, with the appropriate Metadata (title, notebook, tags) and automatically imports it back into Evernote using the Markdown2Evernote command for TextMate. After all this, the script also deletes the old note. A few usage notes: In order to run smoothly, the search for pre-existing notes is limited to notes with the "Wiki" tag. Thus, if you want a note to be 'visible' to the script, you must assign it this tag. Moreover, once your number of Wiki notes grows, this may not be efficient enough anymore. I would add a new tag to your original note and add this into the script as a variable. Also, while you can put non-WikiWord terms into [[double brackets]] in the original note to create new notes, this will create two notes ("double" and "brackets"). I am doing extensive testing now to find any other bugs. Would appreciate any help on that front. I have attached a .txt file with the script below. Wikify Combined.txt Link to comment
Hackademic 8 Posted June 6, 2013 Author Share Posted June 6, 2013 Sorry for multiple posts, but I actually debugged once more. I realized that the scripts were unable to handle input that didn't have links to pre-existing notes and WikiWords. So I wrote in large, wrapping if blocks for the two major halves of the script so that even if you the note doesn't have links to pre-existing notes and/or it doesn't have WikiWords or [[bracketed words]], the script will still function. For example, if you were to run this new script (Version 1.3 of the new combined scripts) on a note with the text: "This note has nothing in it." The script would hastily export a note from TextMate to Evernote with that exact content, but now with the tag "Wiki". This is the last major potential bug I could think of, but if you find any, please let me know and I will see what I can do. Likewise, I have attempted to explain in detail how the script works with extensive commenting, so you may be able to fix it yourself. Either way, please use and post your results. New .txt file below. Wikify Combined v.3.txt Link to comment
Chad Peters 1 Posted June 25, 2013 Share Posted June 25, 2013 Sorry - new guy here. How do I utilize this script? I would really like to have this functionality but I'm unsure how to deploy the concept. Link to comment
Hackademic 8 Posted June 25, 2013 Author Share Posted June 25, 2013 Chad, Happy to help. Not too long ago I was the new guy and spent too much time scouring the forums and the Internet at large to find what I needed, so I know the feeling. I have actually created a sort-of suite of apps and scripts to create various wiki functionalities in Evernote. I would love to send you exactly what you would like best, so could you describe your best use-case?In general though, you need to get the Markdown2Evernote script, which I discuss in an earlier post on this thread. Go to Tim Lockridge's blog (linked in that earlier post) to find a step by step set of instructions. His post is specifically for the text editor TextMate. I would recommend it, but its not necessary. You can also use the Mac's built in TextEditor. If you choose the latter route, you will need to tweak both Tim's instructions (make the script an Automator service) and my script (using TextEditor instead of TextMate). If this is confusing, just outline your ideal situation to use create this functionality, and I'll work to break it down step-by-step for you. Link to comment
Hackademic 8 Posted July 1, 2013 Author Share Posted July 1, 2013 I recently realized that I could utilize TextExpander to simplify this process. Instead of launching the app with a Selection Window with the 4 programs that I might want to embed links from, and then have a Dialog Box that allows me to choose between getting the link of whatever item is currently selected or choosing any item on my own, I have created 8 different snippets that launch the sub-structures of the script. If you have TextExpander (or what I use aText, which has all the same features but is newer and cheaper), then this set-up I find to be simpler and faster. Link to comment
awright3@stanford.edu 0 Posted August 30, 2013 Share Posted August 30, 2013 Hey, I'm totally new to AppleScripts/Mac development, and I can't get this to work. Bummer since it sounds like an awesome feature! Can you tell me what I'm doing wrong? I've save the script to my Mac and when I try running it, it gives me this message: Thanks! -Adam Link to comment
Hackademic 8 Posted September 1, 2013 Author Share Posted September 1, 2013 Adam, I'm so sorry for the long delay. Your post sparked a total reevaluation of the scripts. I had actually stopped using them, but your post reminded me that they were worth making functional. Your particular issue stems from my original scripts being written to work only with the paid version of TextMate. That was foolish and selfish of me. I agree that these are awesome features so I've totally retooled these functions to work with the Markdown2Evernote Mac OS X Service. For this workflow, you write in Markdown syntax in an external editor and then send that Markdown text to Evernote as a HTML note. I've bundled the autolinking to pre-existing notes and to new notes functions into this service. It is now application agnostic, much faster, and much easier. For a fuller description and a download of the service, see my blog post here: http://bit.ly/17eSfGg Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.