Last active
April 21, 2020 12:06
-
-
Save fractaledmind/7668654 to your computer and use it in GitHub Desktop.
This script takes text selected from within an Evernote note and (1) creates a new note whose titles matches the selected text in the same notebook, (2) embeds a link to the original note as the first line of the new note, and (3) replaces the selected text with a link to the newly created note. This allows you to easily create a wiki-like envir…
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
(* CREATE AND AUTOLINK TO NEW NOTE FROM SELECTION | |
--Stephen Margheim | |
--11/26/13 | |
--open source | |
This script takes text selected from within an Evernote note and (1) creates a new note whose titles matches the selected text in the same notebook, (2) embeds a link to the original note as the first line of the new note, and (3) replaces the selected text with a link to the newly created note. | |
This allows you to easily create a wiki-like environment within your Evernote account. | |
*) | |
tell application id "com.evernote.Evernote" | |
set Evernote_Selection to selection | |
if Evernote_Selection is {} then display dialog "Please select a note." | |
repeat with i from 1 to the count of Evernote_Selection | |
--get appropriate note data from current note | |
set noteURL to note link of item i of Evernote_Selection | |
set noteName to title of item i of Evernote_Selection | |
set noteNB to name of notebook of item i of Evernote_Selection | |
set noteHTML to HTML content of item i of Evernote_Selection | |
--generate the hyperlink | |
set html_ref to "<a href=\"" & noteURL & "\">" & noteName & "</a>" | |
--get the selected text from the clipboard | |
set newTitle to the clipboard | |
--create the new note, with the hyperlink back | |
set newNote to create note title newTitle with html html_ref notebook noteNB | |
--synchronize to assign server data to new note | |
repeat until isSynchronizing is false | |
end repeat | |
synchronize | |
repeat until isSynchronizing is false | |
end repeat | |
--get appropriate data of the new note | |
set newURL to note link of newNote | |
set newName to title of newNote | |
set newhtml_ref to "<a href=\"" & newURL & "\">" & newName & "</a>" | |
--replace the selected text with a hyperlink | |
set newHTML to my replaceString(noteHTML, newTitle, newhtml_ref) | |
set HTML content of item i of Evernote_Selection to newHTML | |
--synchronize again to finalize everything | |
repeat until isSynchronizing is false | |
end repeat | |
synchronize | |
repeat until isSynchronizing is false | |
end repeat | |
end repeat | |
end tell | |
(* HANDLERS *) | |
on replaceString(theText, oldString, newString) | |
-- ljr (http://applescript.bratis-lover.net/library/string/) | |
local ASTID, theText, oldString, newString, lst | |
set ASTID to AppleScript's text item delimiters | |
try | |
considering case | |
set AppleScript's text item delimiters to oldString | |
set lst to every text item of theText | |
set AppleScript's text item delimiters to newString | |
set theText to lst as string | |
end considering | |
set AppleScript's text item delimiters to ASTID | |
return theText | |
on error eMsg number eNum | |
set AppleScript's text item delimiters to ASTID | |
error "Can't replaceString: " & eMsg number eNum | |
end try | |
end replaceString |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment