Skip to content

Instantly share code, notes, and snippets.

@csreed
Last active October 24, 2021 13:13
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save csreed/2a7f625ced450bdc76891893c54783cf to your computer and use it in GitHub Desktop.
Save csreed/2a7f625ced450bdc76891893c54783cf to your computer and use it in GitHub Desktop.
Create a project support note in Evernote. The note will be cross-referenced with the task/project in OmniFocus.
(*
Opens the support note for an OmniFocus task/project in Evernote. Creates the note if necessary, linking the note back to the task/project.
NB: If you set this up by hand, the evernote:/// URL in OmniFocus needs to be enclosed in <> for the script to find it.
Put this script in ~/Library/Application Scripts/com.omnigroup.omnifocus2. Then you can add the script as a custom toolbar item.
version 1.0: Initial release
*)
property notebookName : "Planner"
on run
set theURL to my getExistingNoteURL()
if theURL is equal to "" then
set theURL to my makeNewNoteURL()
end if
my viewNote(theURL)
end run
(*
Checks for an existing note.
Returns the note's URL if found, "" if not.
*)
on getExistingNoteURL()
tell application "OmniFocus"
tell front window
set the_task to value of item 1 of selected trees of content
set existing_note_value to the_task's note
set p1 to offset of "evernote:///" in existing_note_value
if p1 is 0 then
return ""
end if
set the_existing_url to text p1 through -1 of existing_note_value
set p2 to offset of ">" in the_existing_url
if p2 is not 0 then
set the_existing_url to text 1 through (p2 - 1) of the_existing_url
end if
return the_existing_url
end tell
end tell
end getExistingNoteURL
(*
Makes a new support note, cross-referenced to the selected OmniFocus task/project.
*)
on makeNewNoteURL()
(* Collect information from the selected OmniFocus task/project *)
tell application "OmniFocus"
tell front window
set the_task to value of item 1 of selected trees of content
set the_task_link to "omnifocus:///task/" & (the_task's id)
set the_task_name to the_task's name
set the_due_date to the_task's due date
end tell
end tell
(* Create a note in Evernote *)
tell application "Evernote"
set the_notebook to notebook notebookName
set the_note to create note with html "" title the_task_name notebook the_notebook
tell the_note
set source URL to the_task_link
set reminder time to the_due_date
end tell
-- The note link for new notes isn’t available until the note has synced.
my synchronizeEvernote()
set the_note_link to the_note's note link
end tell
(* Add note link to OmniFocus task *)
tell application "OmniFocus"
set link_text to "Evernote <" & the_note_link & ">"
set current_note to the_task's note
if current_note is equal to "" then
set the_task's note to link_text
else
set the_task's note to (current_note & "
" & link_text)
end if
end tell
return the_note_link
end makeNewNoteURL
(*
We only have the `synchronize` command, which initiates a sync and returns immediately.
So start the sync and poll every 250ms.
*)
on synchronizeEvernote()
tell application "Evernote"
synchronize
repeat while isSynchronizing
delay 0.25
end repeat
end tell
end synchronizeEvernote
(*
Tell Evernote to show the note.
*)
on viewNote(theURL)
tell application "Evernote"
activate (open location theURL)
end tell
end viewNote
@acrolyos
Copy link

Hi @csreed. Thank you for building this.

I am not able to make it work. I think this is related to the statement

" NB: If you set this up by hand, the evernote:/// URL in OmniFocus needs to be enclosed in <> for the script to find it."

I can install and make it run in OF2. But I get:

  • A note in Eveernote with the name of the task
  • Note in Evernote does not have a link back to the task in OF2
  • The Task in OF2 shows "Evernote "

I have created a notebook on evernote called "Planner"

What am I doing wrong?

Thank you!

@Dave-Snigier
Copy link

This is a beautiful script. Elegant solution to the problem and well-written to boot. Links work perfectly on IOS and MacOS

Thank you so much for sharing!

@facilitated
Copy link

I've been using this script for years - and would miss it terribly if I couldn't use it. And now, on my new Mac, I suddenly get this error message:

The operation couldn’t be completed. /Users/fdx247/Library/Application Scripts/com.omnigroup.OmniFocus3/Support Note.scpt:1874:1886: script error: Expected end of line, etc. but found identifier. (-2741)

Referring to this line: set the_notebook to notebook notebookName
I've changed the first line to match my default notebook: property notebookName : "@inbox"

But when compiling it in the script editor i get the same error.

@facilitated
Copy link

Found the answer: Evernote V10 does not support AppleScript... go figure...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment