-
-
Save nicksieger/1548689 to your computer and use it in GitHub Desktop.
OmniFocus integrations
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
-- from http://veritrope.com/code/copy-omnifocus-item-uri-to-evernote/ | |
tell front window of application "OmniFocus" | |
try | |
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 | |
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:///project/" & id of theSelection | |
set theNote to "" | |
else | |
set theURI to "omnifocus:///task/" & id of theSelection | |
set theNote to note of theSelection | |
set theProjectName to name of containing project of theSelection | |
end if | |
set theName to name of theSelection | |
tell application "Evernote" | |
set newNote to create note with text theURI & return & theNote | |
set title of newNote to theName | |
set source URL of newNote to theURI | |
if (count of theProjectName) > 0 then | |
if (not (tag named theProjectName exists)) then | |
make tag with properties {name:theProjectName} | |
end if | |
set theTag to tag named theProjectName | |
assign theTag to newNote | |
end if | |
open note window with newNote | |
activate | |
end tell | |
end try | |
end tell |
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
on openQuickEntry(theTitle, theTaskNote) | |
tell application "OmniFocus" to tell default document | |
tell quick entry | |
set theTask to make new inbox task with properties {name:theTitle} | |
select {theTask} | |
set note of theTask to theTaskNote | |
set note expanded of last tree to true | |
open | |
tell application "System Events" to keystroke tab | |
end tell | |
end tell | |
end openQuickEntry | |
-- Chrome handling based on post by iNik: http://forums.omnigroup.com/showthread.php?p=101947#post101947 | |
on fromGoogleChrome() | |
set theTitle to "" | |
set theTaskNote to "" | |
tell application "Google Chrome" | |
-- activate | |
tell window 1 to tell active tab | |
set oldClipboard to text of (the clipboard) | |
log result | |
copy selection | |
set theTitle to title | |
set theURL to URL | |
set theTaskNote to theURL | |
set newClipboard to text of (the clipboard) | |
log result | |
if newClipboard is not equal to oldClipboard then | |
set theTaskNote to theTaskNote & (return) & (return) & newClipboard | |
end if | |
end tell | |
end tell | |
openQuickEntry(theTitle, theTaskNote) | |
end fromGoogleChrome | |
-- Make a new Omnifocus task from the current selection in Evernote | |
-- The note title becomes the task title, and a link is provided back to the Evernote note | |
on fromEvernote() | |
set theTitle to "" | |
set theTaskNote to "" | |
tell application "Evernote" | |
set noteList to selection | |
set currentEvernote to item 1 of noteList | |
set theTitle to title of currentEvernote | |
set theTaskNote to note link of currentEvernote | |
if (theTaskNote is missing value) then | |
synchronize | |
repeat 6 times | |
delay 0.25 | |
set theTaskNote to note link of currentEvernote | |
if (theTaskNote is not missing value) then | |
exit repeat | |
end if | |
end repeat | |
if (theTaskNote is missing value) then | |
display dialog "Sync was needed and is taking a while; dismiss me when sync is complete" | |
set theTaskNote to note link of currentEvernote | |
end if | |
end if | |
if (source URL of currentEvernote is not missing value) then | |
set theTaskNote to source URL of currentEvernote & (return) & (return) & theTaskNote | |
end if | |
end tell | |
openQuickEntry(theTitle, theTaskNote) | |
end fromEvernote | |
-- on fromFirefox() | |
-- set theTitle to "" | |
-- set theTaskNote to "" | |
-- tell application "Firefox" | |
-- activate | |
-- tell application "System Events" | |
-- keystroke "l" using {command down} | |
-- keystroke "c" using {command down} | |
-- end tell | |
-- set theTaskNote to text of (the clipboard) | |
-- set theTitle to name of front window | |
-- end tell | |
-- openQuickEntry(theTitle, theTaskNote) | |
-- end fromFirefox | |
on fromSafari() | |
set theTitle to "" | |
set theTaskNote to "" | |
tell application "Safari" | |
set theTitle to name of current tab of front window as string | |
set theTaskNote to URL of current tab of front window as string | |
end tell | |
openQuickEntry(theTitle, theTaskNote) | |
end fromSafari | |
on fromUnknown(theFrontApp) | |
set theTitle to "" | |
set theTaskNote to "" | |
-- FIXME: don't need to tell theFrontApp anything right now; | |
-- for possible future hax | |
tell application theFrontApp | |
try | |
set theTitle to name of front window | |
set theTaskNote to "" | |
on error errMsg | |
-- display dialog "ERROR: " & errMsg | |
-- skip trying to set task title | |
set theTitle to "" | |
set theTaskNote to "" | |
end try | |
end tell | |
openQuickEntry(theTitle, theTaskNote) | |
end fromUnknown | |
tell application "System Events" | |
set theFrontApp to name of first application process whose frontmost is true | |
if theFrontApp = "Evernote" then | |
set result to my fromEvernote() | |
else if theFrontApp = "Safari" then | |
set result to my fromSafari() | |
else if theFrontApp = "Google Chrome" then | |
set result to my fromGoogleChrome() | |
-- else if theFrontApp = "Firefox" then | |
-- set result to my fromFirefox() | |
else | |
set result to my fromUnknown(theFrontApp) | |
end if | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment