-
-
Save dgreen/26808fa60bd5ba222fa516aceb11f778 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.
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
(* | |
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 : ".Inbox" | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found based on reference here: https://learnomnifocus.com/resources/applescript/