Skip to content

Instantly share code, notes, and snippets.

@FokkeZB
Last active February 24, 2018 02:01
Show Gist options
  • Save FokkeZB/5093218 to your computer and use it in GitHub Desktop.
Save FokkeZB/5093218 to your computer and use it in GitHub Desktop.
AppleScript to create a task in Things to help you follow up on stuff you've asked people
using terms from application "Mail"
on perform mail action with messages theMessages
tell application "Mail"
repeat with eachMessage in theMessages
set theSubject to subject of eachMessage
set theMessageId to message id of eachMessage
set theRecipientName to name of first to recipient of eachMessage
set toDoName to theRecipientName & ": " & theSubject
set toDoContent to "[url=message:%3C" & ¬
theMessageId & ¬
"%3E]" & ¬
theSubject & ¬
"[/url]"
set toDoDueDate to (current date) + 7 * days
set toDoProjectName to "#Delegated"
my createThingsToDo(toDoName, toDoContent, missing value, toDoDueDate, missing value, missing value, toDoProjectName)
end repeat
end tell
end perform mail action with messages
end using terms from
on createThingsToDo(toDoName, toDoContent, toDoStartDate, toDoDueDate, toDoTagsString, toDoCompletionDate, toDoProjectName)
tell application "Things"
if toDoProjectName is "Tasks" then
set toDoProjectName to missing value
end if
set newT to make new to do with properties {name:toDoName}
if toDoContent is not missing value then
set notes of newT to toDoContent
end if
move newT to list "Next"
if toDoDueDate is not missing value then
set due date of newT to toDoDueDate
end if
if toDoProjectName is not missing value then
set project of newT to project toDoProjectName
if toDoStartDate is not missing value then
if my isDateToday(toDoStartDate) then
move newT to list "Today"
end if
end if
else
if toDoStartDate is not missing value then
if my isDateToday(toDoStartDate) then
move newT to list "Today"
else
schedule newT for toDoStartDate
end if
end if
end if
if toDoTagsString is not "" then
set tag names of newT to toDoTagsString
end if
if toDoCompletionDate is not missing value then
move newT to list "Logbook"
set completion date of newT to toDoCompletionDate
end if
end tell
return newT
end createThingsToDo
on isDateToday(d)
set td to current date
set hours of td to 0
set minutes of td to 0
set seconds of td to 0
return (d is td)
end isDateToday
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment