Skip to content

Instantly share code, notes, and snippets.

@ncarboni
Last active August 29, 2015 14:14
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 ncarboni/e44e746a5716b48e14ea to your computer and use it in GitHub Desktop.
Save ncarboni/e44e746a5716b48e14ea to your computer and use it in GitHub Desktop.
Applescript for automatically send message with Orange Flag to omnifocus (with link to the original message in note) and change the flag to Yellow
on run
-- based on Hunter Hillegas' original script at https://github.com/HunterHillegas/OmniFocusMailFlags
-- and on David Timothy Duval https://gist.github.com/dtduval/7866363
if application "Mail" is running then tell application "Mail"
set _msgs_to_capture to (every message of inbox whose flag index is 1)
repeat with eachMessage in _msgs_to_capture
set theStart to missing value
set theDue to missing value
set theOmniTask to missing value
set theTitle to the subject of eachMessage
set theNotes to the content of eachMessage
set theCombinedBody to "message://%3c" & message id of eachMessage & "%3e"
tell application "OmniFocus"
tell default document
set newTaskProps to {name:theTitle}
if theStart is not missing value then set newTaskProps to newTaskProps & {defer date:theStart}
if theDue is not missing value then set newTaskProps to newTaskProps & {due date:theDue}
if theCombinedBody is not missing value then set newTaskProps to newTaskProps & {note:theCombinedBody}
set newTask to make new inbox task with properties newTaskProps
end tell
end tell
set flag index of eachMessage to 2
end repeat
end tell
end run
@ncarboni
Copy link
Author

ncarboni commented May 8, 2015

edit 1: add the possibility to run the script only if mail is running (otherwise keyboard maestro would open the app all the time)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment