Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save deasmi/1545766 to your computer and use it in GitHub Desktop.
Save deasmi/1545766 to your computer and use it in GitHub Desktop.
Evernote and OmniFocus integration
-- Find the note in omnifocus for the current project / folder
-- (or create a new one) and display it.
-- Created by Mark Fowler (mark@twoshortplanks.com)
-- Help from http://veritrope.com/code/search-evernote-for-notes-containing-link-to-selected-omnifocus-item/
-- on getting the name / url for the current omnifocus item
tell front window of application "OmniFocus"
try
-- work out what is selected in omnifocus
set theTrees to selected trees of content
if (count of theTrees) < 1 then
set theTrees to selected trees of sidebar
end if
if (count of theTrees) < 1 then
return
end if
set theSelection to value of item 1 of theTrees
-- work out the URL that would link to that
if class of theSelection is folder then
set theURI to "omnifocus:///folder/" & id of theSelection
set theNote to ""
else if class of theSelection is project then
set theURI to "omnifocus:///task/" & id of theSelection
set theNote to ""
else
-- link tasks to the project that contains them, not the task itself
set theNote to note of theSelection
set theProjectName to name of containing project of theSelection
set theURI to "omnifocus:///task/" & id of containing project of theSelection
end if
-- work out the name
set theName to name of theSelection
-- create / find a note in evernote
tell application "Evernote"
-- work out the search string that can be used to find anything
-- that has the source url
set theQueryString to "sourceURL:" & theURI
-- look for existing notes with that querty string
set existingNotes to {}
set existingNotes to find notes theQueryString
if (count of existingNotes) = 0 then
-- no note found, create a new one
set newNote to create note with text "" & return & theNote
set title of newNote to theName
set source URL of newNote to theURI
end if
-- show the note(s)
activate
open collection window with query string theQueryString
end tell
end try
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment