Skip to content

Instantly share code, notes, and snippets.

@brandonpittman
Last active September 3, 2016 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonpittman/cba56ec694313d3827f9bf215371f497 to your computer and use it in GitHub Desktop.
Save brandonpittman/cba56ec694313d3827f9bf215371f497 to your computer and use it in GitHub Desktop.
Send available OmniFocus tasks to an email address
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
# classes, constants, and enums used
property NSCaseInsensitiveSearch : a reference to 1
property NSString : a reference to current application's NSString
set taskList to {}
tell application "OmniFocus"
tell default document
repeat with _project in (every flattened project whose number of available tasks > 0)
set the end of taskList to (get (name of _project) & ":")
repeat with _task in (every flattened task of _project whose blocked is false and completed is false)
set the end of taskList to " - " & (get name of _task) & " @" & (get name of context of _task)
end repeat
end repeat
end tell
end tell
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {","}
set taskList to taskList as string
set AppleScript's text item delimiters to saveTID
set aString to NSString's stringWithString:taskList
set taskList to (aString's stringByReplacingOccurrencesOfString:"," withString:"
" options:NSCaseInsensitiveSearch range:{0, aString's |length|()}) as text
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:"Today's Tasks", content:taskList & return & return}
tell newMessage
set visible to true
make new to recipient at end of to recipients with properties {address:"some email address"}
end tell
send newMessage
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment