Last active
August 29, 2015 14:18
-
-
Save kenjitayama/641580534179dc8292d0 to your computer and use it in GitHub Desktop.
Create Evernote notes from selected task in OmniFocus2.
This file contains 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
(* | |
# DESCRIPTION # | |
Create Evernote note from selected task in OmniFocus2. | |
Also creates cross reference (links) to the task note and Evernote note. | |
*) | |
on main() | |
tell application "OmniFocus" | |
tell content of first document window of front document | |
--Get selection | |
set validSelectedItemsList to value of (selected trees where class of its value is not item and class of its value is not folder) | |
set totalItems to count of validSelectedItemsList | |
if totalItems is 0 then | |
my notify("No valid task(s) selected") | |
return | |
end if | |
repeat with thisItem in validSelectedItemsList | |
my createEnNoteWithItem(thisItem) | |
end repeat | |
end tell | |
end tell | |
end main | |
(* | |
Edit following to map OmniFocus projects to Evernote notebooks | |
*) | |
on notebookNameFromProject(taskProject) | |
if taskProject is missing value then | |
return missing value | |
end if | |
set projectName to name of taskProject | |
if projectName is equal to "Finance" then | |
return "Finance" | |
else if projectName is equal to "Home" then | |
return "Home" | |
else | |
return missing value | |
end if | |
end notebookNameFromProject | |
on createEnNoteWithItem(selectedItem) | |
set taskTitle to name of selectedItem | |
set taskUrl to "omnifocus:///task/" & id of selectedItem | |
set taskLink to "<a href=\"" & taskUrl & "\">OmniFocus Task</a>" | |
set taskNote to note of selectedItem | |
set noteContent to taskLink & "<br>" & taskNote | |
set taskProject to containing project of selectedItem | |
set notebook to my notebookNameFromProject(taskProject) | |
set noteLink to my createEnNote(taskTitle, noteContent, notebook) | |
set newTaskNote to noteLink & "\n" & taskNote | |
set note of selectedItem to newTaskNote | |
my notify("created note!") | |
return | |
end createEnNoteWithItem | |
on createEnNote(taskTitle, noteContent, notebookTitle) | |
tell application "Evernote" | |
set noteLink to missing value | |
-- assure sync is not running | |
repeat until isSynchronizing is false | |
end repeat | |
if notebook is missing value then | |
set newNote to create note title taskTitle with html noteContent | |
else | |
set newNote to create note title taskTitle notebook notebookTitle with html noteContent | |
end if | |
-- synchronize and get note link | |
synchronize | |
repeat while noteLink is missing value | |
set noteLink to (note link of newNote) | |
end repeat | |
return noteLink | |
end tell | |
end createEnNote | |
on notify(alertText) | |
tell application "OmniFocus" to display dialog alertText with icon 1 buttons {"OK"} default button "OK" | |
end notify | |
main() |
This file contains 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
#!/bin/sh | |
cp *.scpt "$HOME/Library/Application Scripts/com.omnigroup.OmniFocus2.MacAppStore/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment