Skip to content

Instantly share code, notes, and snippets.

@poritsky
Last active October 27, 2018 07:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poritsky/5272217 to your computer and use it in GitHub Desktop.
Save poritsky/5272217 to your computer and use it in GitHub Desktop.
A work-in-progress script to add MailTags keywords to messages in Mail based on sender. Uses GUI scripting and you'll have to jump through some hoops to add this to a workflow, but it may be of use. Toughest part is adding new addresses to it. Also note: the tags in the script must "Preferred Keywords" to be in your menubar.
# Automate MailTags Tagging
# by Jonathan Poritsky
# http://candlerblog.com
#
# Instructions for editing inline.
tell application "Mail"
activate
set m to (selection)
set s to (extract address from sender of item 1 of m)
if (s contains "@gmail.com") or (s contains "jerk@yahoo.com") then --edit email addresses in quotes. To add more addresses add another "or (s contains...)" before "then".
tell application "System Events"
tell menu "Add MailTags Keyword" of menu item "Add MailTags Keyword" of menu "MailTags" of menu item "MailTags" of menu "Message" of menu bar item "Message" of menu bar 1 of application process "Mail"
click menu item "@tag" --pick your tag name here
end tell
end tell
else if (s contains "otheraddress@whatever.com") then --Same as above
tell application "System Events"
tell menu "Add MailTags Keyword" of menu item "Add MailTags Keyword" of menu "MailTags" of menu item "MailTags" of menu "Message" of menu bar item "Message" of menu bar 1 of application process "Mail"
click menu item "@othertag" --Here's the next tag
end tell
end tell
-- Copy and paste from previous "else if" to here to add more rules for tags.
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment