Skip to content

Instantly share code, notes, and snippets.

@byronrode
Created April 28, 2012 01:12
Show Gist options
  • Save byronrode/2514866 to your computer and use it in GitHub Desktop.
Save byronrode/2514866 to your computer and use it in GitHub Desktop.
Create To Do in Things
Using Mail.app and creating a custom rule, this AppleScript will enable you to send an email with a list of items to be added to the Inbox or Project (using the Subject).
How to use:
1. Save this script to your ~/Library/Scripts folder or a folder of your choice.
2. Create a new email address for receiving to do's and set it the account in Mail.
3. Add a new rule in Preferences. Give it a name and set a condition for all mails received at the address in 2 above, to be marked as read, deleted and then finally run an ApplesScript.
4. Choose the AppleScript from the location you save it in.
5. Save the rule and don't apply it to your emails in your inbox already.
6. Send an email to your chosen email address from another address or your phone, specifying a new or existing Project as a subject, or leave it (the subject) blank to put the new to do(s) in the Things Inbox.
7. Type each task you want to add on a new line.
8. If you have a signature that is prefixed with "--" it will automagically stop processing the mail once it reaches there, otherwise remove your signature from your mail.
9. Done.
NB: Be sure to replace "Things beta" with "Things" if you are not running the beta version of Things.
on perform_mail_action(info)
set selectedMessages to |SelectedMessages| of info
tell application "Mail"
repeat with eachMessage in selectedMessages
set theSubject to the subject of the eachMessage
set theContent to the content of the eachMessage
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ASCII character 10 -- (a line feed)
set theItem to text items of theContent
set AppleScript's text item delimiters to tid
tell application "Things beta"
set allProjects to name of to dos of list "Projects"
set theProject to ""
-- the subject is not blank, therefore it must be project based
if theSubject as string is not equal to "" then
-- there are no existing projects so don't iterate through
if (count of allProjects) is equal to 0 then
set newProject to make new project with properties {name:theSubject}
set theProject to theSubject
return my createToDo(true, theItem, theProject)
else
repeat with aProject in allProjects
if aProject as string is equal to theSubject then
set theProject to aProject
return my createToDo(true, theItem, theProject)
else
set newProject to make new project with properties {name:theSubject}
set theProject to theSubject
return my createToDo(true, theItem, theProject)
end if
end repeat
end if
else
-- the subject is empty so place it in the Inbox
return my createToDo(false, theItem, theProject)
end if
end tell
end repeat
end tell
end perform_mail_action
on createToDo(isProject, tdItem, tdProject)
if class of tdItem is equal to list then
repeat with i in tdItem
if i as string is equal to "--" then
return
else
my createToDo(isProject, i, tdProject)
end if
end repeat
else
tell application "Things beta"
if tdItem as string is not equal to "" then
if isProject is true then
set newToDo to make new to do with properties ¬
{name:tdItem} at beginning of project tdProject
else
set newToDo to make new to do with properties ¬
{name:tdItem}
end if
end if
end tell
end if
return
end createToDo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment