Skip to content

Instantly share code, notes, and snippets.

@dpinney
Last active December 8, 2023 23:15
Show Gist options
  • Save dpinney/2c40682ac5da29cd55c563a2b69c3a88 to your computer and use it in GitHub Desktop.
Save dpinney/2c40682ac5da29cd55c563a2b69c3a88 to your computer and use it in GitHub Desktop.
AppleScript to create calendar events reminding you to follow up on Mail.app messages
-- Create a calendar event reminding you to follow up on the currently selected email.
-- Note that this puts everything on a calendar named "Todo" and will fail if that calendar doesn't exist.
-- By David@Pinney.org on 18 June 2017
on run
tell application "Mail"
set s to selection
if (count of s) is not 1 then
display dialog "Please select exactly one message." buttons {"OK"}
return
end if
# If we want to do multiple messages, then 'repeat with i from 1 to the count of s'
set msg to item 1 of s
set msgsubject to subject of msg
set msgsender to sender of msg
set msgid to message id of msg
set msgsenddate to date sent of msg
set selectedTime to (choose from list {"day", "week", "month"} with prompt "Remind after one:" default items "Day") as string
if selectedTime is "false" then return
tell application "Calendar" to tell calendar "Todo"
set currentTimeRoundedToHour to (current date) - (minutes of (current date)) * minutes - (seconds of (current date))
if selectedTime is "day" then
set starttime to currentTimeRoundedToHour + 1 * days
else if selectedTime is "week" then
set starttime to currentTimeRoundedToHour + 1 * weeks
else if selectedTime is "month" then
set starttime to currentTimeRoundedToHour + 4 * weeks
end if
set endtime to starttime + 60 * minutes
set theEvent to make new event with properties {start date:starttime, end date:endtime, summary:"Check on " & msgsender & " - " & msgsubject}
set description of theEvent to "Email arrived on " & msgsenddate
set url of theEvent to "message://" & "%3c" & msgid & "%3e"
end tell
display dialog "Calendar reminder set one " & selectedTime & " from today about " & msgsender & " - " & msgsubject buttons {"OK"} default button 1
end tell
end run
@dpinney
Copy link
Author

dpinney commented Jun 19, 2017

Easiest way to install this: open Automator.app, create a new service, make it for Mail.app only with no input, add an Applescript action and paste in this code, and save the service. It will now show up in your services menu in Mail.app, and you can assign a keyboard shortcut to it in the Keyboard pane in System Preferences.

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