Skip to content

Instantly share code, notes, and snippets.

@jeredb
Created February 16, 2011 03:26
Show Gist options
  • Save jeredb/828803 to your computer and use it in GitHub Desktop.
Save jeredb/828803 to your computer and use it in GitHub Desktop.
--by Don Southard aka @binaryghost adapted by Ben Brooks aka @benjaminbrooks, adapted by Jered Benoit aka @jeredb - 20113415
-- Variables
-- Email Subject Line
set mailSubject to "Delegated Task from Jered Benoit: "
-- Include "Send to Omnifocus" link
set sendToOmnifocus to true
-- Include "Open in Omnifocus" link
set openInOmniFocus to true
-- Defer Applescript location
-- Available from: http://bylr.net/files/omnifocus/
set runDeferScript to true
-- Has to be full path (no "~")
set DeferScript to "/Users/Jeredb/Library/Scripts/Applications/OmniFocus/Defer.scpt"
-- Delegate Applescript location
-- Available from: http://www.cerquant.com/software
set runDelegateScript to true
-- Has to be full path (no "~")
set DelegatedScript to "/Users/Jeredb/Library/Scripts/Applications/OmniFocus/Delegated.scpt"
on urlencode(theText)
set theTextEnc to ""
repeat with eachChar in characters of theText
set useChar to eachChar
set eachCharNum to ASCII number of eachChar
if eachCharNum = 32 then
set useChar to "%20"
else if (eachCharNum ≠ 42) and (eachCharNum ≠ 95) and (eachCharNum < 45 or eachCharNum > 46) and (eachCharNum < 48 or eachCharNum > 57) and (eachCharNum < 65 or eachCharNum > 90) and (eachCharNum < 97 or eachCharNum > 122) then
set firstDig to round (eachCharNum / 16) rounding down
set secondDig to eachCharNum mod 16
if firstDig > 9 then
set aNum to firstDig + 55
set firstDig to ASCII character aNum
end if
if secondDig > 9 then
set aNum to secondDig + 55
set secondDig to ASCII character aNum
end if
set numHex to ("%" & (firstDig as string) & (secondDig as string)) as string
set useChar to numHex
end if
set theTextEnc to theTextEnc & useChar as string
end repeat
return theTextEnc
end urlencode
if runDeferScript is true then run script (DeferScript)
if runDelegateScript is true then run script (DelegatedScript)
tell application "OmniFocus"
tell front document
tell (first document window whose index is 1)
set SelectedItemInMainView to selected trees of content
try
set theSelectedTask to value of item 1 of SelectedItemInMainView
set nameSelectedTask to name of theSelectedTask
set noteSelectedTask to note of theSelectedTask
set idSelectedTask to id of theSelectedTask
-- set contextSelectedTask to name of the context of theSelectedTask
set encodedName to my urlencode(nameSelectedTask as rich text)
set encodedNote to my urlencode(noteSelectedTask as rich text)
set addToOFLink to "<omnifocus:///add?name=" & encodedName & "&note=" & encodedNote & ">"
set openInOFLink to "<omnifocus:///task/" & idSelectedTask & ">"
set mailSubject to mailSubject & nameSelectedTask
set mailContent to nameSelectedTask & return & "Note: " & noteSelectedTask & return
if sendToOmnifocus is true then set mailContent to mailContent & "Add this task to Omnifocus: " & addToOFLink
if openInOmniFocus is true then set mailContent to mailContent & return & "Open in Omnifocus: " & openInOFLink
on error err
display dialog "No task selected!" with icon caution
end try
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:mailSubject, content:mailContent}
tell newMessage
-- Default is false. Determines whether the compose window will
-- show on the screen or whether it will happen in the background.
set visible to true
tell content
end tell
end tell
-- Bring the new compose window to the foreground, in all its glory
activate
end tell
end tell
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment