Skip to content

Instantly share code, notes, and snippets.

@ot-joe-ocampo
Last active August 29, 2015 14:09
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 ot-joe-ocampo/2d93761cf1277e7c198c to your computer and use it in GitHub Desktop.
Save ot-joe-ocampo/2d93761cf1277e7c198c to your computer and use it in GitHub Desktop.
tell application "Mail"
-- Gets the selected message from Mail and gets
-- basic information from the message to be used
-- later to process into OF2
set selected_messages to get selection
set the selected_message to item 1 of the selected_messages
set msg_id to the message id of the selected_message
set msg_subject to the subject of selected_message
set msg_body to the content of selected_message
set msg_url to "message://%3c" & msg_id & "%3e"
-- Gets the the name of who sent the email
-- and their email address
tell (sender of selected_message)
set theFromName to (extract name from it)
set theFromAddress to (extract address from it)
end tell
-- Check VIP list in Mail, if the email address
-- matches the list then Flag the task in OF2
set emailAddress to word 1 of theFromAddress
set taskFlag to false
if (my getVIPs() as string) contains emailAddress then
set taskFlag to true
end if
-- send message to omniFocus
my send_message_to_omniFocus(msg_subject, msg_url, msg_body, theFromName, taskFlag)
-- archive the message that was processed to OF2
tell application "Mail"
set destinationFolderName to "Archive"
set acct to account of mailbox of selected_message
set archiveFolder to mailbox destinationFolderName of acct
move selected_message to archiveFolder
end tell
end tell
on send_message_to_omniFocus(subject, msg_url, body, sender, flag)
tell application "OmniFocus"
-- Check to see if the OF is running
if not my ApplicationIsRunning("OmniFocus") then
activate
end if
-- creates the task and sends it to the inbox on OF
set task_note to msg_url & linefeed & body
set task_title to "Read email ( " & subject & " ) From: " & sender
tell default document
set newTask to make new inbox task with properties {name:task_title, note:task_note, flagged:flag}
end tell
end tell
end send_message_to_omniFocus
on getVIPs()
-- gets the VIPs email address list from plist file in Mail
tell application "System Events"
return get value of property list item "Addresses" of property list items of property list item "Senders" of property list file "~/Library/Mail/V2/MailData/VIPSenders.plist/"
end tell
end getVIPs
on ApplicationIsRunning(appName)
tell application "System Events" to set appNameIsRunning to exists (processes where name is appName)
return appNameIsRunning
end ApplicationIsRunning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment