using terms from application "Mail"
# Set the name of the list where to create the reminder
set InboxName to "_Inbox"
# Set the color of the message (used to mark the message after being linked to Reminders)
set MessageColor to green
# Set the Folder to file the Message in after creating action
set Filebox to mailbox "Inbox/@Reference" of account "NameOfMailMailAccountInMailAppDisplay"
# Set the name of the list where to create project reminders
set ProjectListName to "Projects"
# Turn on or off the prompting for which Action List
set PlaceActionsInInbox to false
# Set the names of your Actions Lists in the Reminders App
set AvailableLists to {"_Inbox", "@Agendas", "@Afterhours", "@Calls", "@Computer", "@Desk", "@Errands", "@Home", "@WaitingFor", "SomeDay/Maybe"}
# set the default reminder due date
set ReminderDueDate to 0
# Turn Reminder on or off
set RemindMeOn to 0
# set the prefix to be prepended to the reminders' name
set ReminderPrefix to ""
#### END of Configuration ####
# Find the selected mail message
set selectedMessages to selection
if (count of selectedMessages) is greater than 0 then
set theMessage to item 1 of selectedMessages
# Get the message properties
set theSubject to my trimText(subject of theMessage)
set theSender to sender of theMessage
set theMessageId to my replaceText("%", "%25", message id of theMessage)
set theTags to "Mail"
# if we have a message with no ID then we give up, since we can't create a link
# based on an empty id
if theMessageId is "" then
display dialog "Can't link this message to Reminders"
return
end if
# build the reminder properties
set message_url to "message:%3C" & theMessageId & "%3E"
set suggestedSubject to my replaceText(return, "", ReminderPrefix & theSubject & "(" & theSender & ")")
display dialog suggestedSubject
# Get the Action statement or Project description from user
set prompt1 to display dialog "Enter Action Statement or Project Description" default answer suggestedSubject buttons {"Action", "Project", "Cancel"} default button "Action"
set finalSubject to the text returned of prompt1
if finalSubject is not "" then set todo_name to my trimText(the text returned of prompt1)
set theList to the button returned of prompt1
#react to button pushed
if theList is equal to "Project" then
set targetList to ProjectListName
else if theList is equal to "Action" then
#Put in Inbox or ask for Action List based on mode
if PlaceActionsInInbox then
set targetList to InboxName
else
set myChoice to (choose from list AvailableLists with title "Action Lists" with prompt "Put in List")
set targetList to item 1 of myChoice
end if
else
set targetList to "Cancel"
end if
if theList is equal to "Cancel" or finalSubject is "" then end run
tell application "System Events" to set frontmost of process "Reminders" to true
tell application "Reminders"
# Search for the proper list where to create the reminder
repeat with listIndex from 0 to (count of list)
set oneList to list listIndex
set listId to id of oneList
if (name of oneList) is equal to targetList then
# create the reminder based on the selected mail
if RemindMeOn is equal to 0 then
set mailReminder to make new reminder with properties {name:todo_name, body:message_url, container:oneList}
else
set mailReminder to make new reminder with properties {name:todo_name, body:message_url, container:oneList, due date:((current date) + (ReminderDueDate * days))}
end if
oneList show
end if
end repeat
end tell
# finally mark the message
set the background color of theMessage to MessageColor
move theMessage to Filebox
end if
end using terms from
# Trims the unnecessary whitespace from someText
on trimText(someText)
set theseCharacters to {" ", tab, ASCII character 10, ASCII character 13, ASCII character 0}
repeat until first character of someText is not in theseCharacters
set someText to text 2 thru -1 of someText
end repeat
repeat until last character of someText is not in theseCharacters
set someText to text 1 thru -2 of someText
end repeat
return someText
end trimText
on replaceText(find, replace, subject)
set previousDelimiters to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set subject to text items of subject
set text item delimiters of AppleScript to replace
set subject to "" & subject
set text item delimiters of AppleScript to previousDelimiters
return subject
end replaceText