Friday, January 9, 2015

Create new Todoist task from Mac Outlook

It can be very challenging if you are in the midst of dozens of emails a day to even get near a zero-inbox.  As of this writing, I am over 300 messages sitting in my inbox.  I have a relatively simple AppleScript which I have pieced together from a few different sources.

First, copy the script (below) to your local machine into your user folder ~/Library/Application Support/Microsoft/Office/Outlook Script Menu Items.

You can navigate to that path in a new Finder window by holding the Option key and opening the Go menu.  You should see the Library option appear there.  Now, just follow the path to the location mentioned above.

After you create  the file there, create the file todoist-token.txt. In this file, you'll want to copy the API token from your account in Todoist.  Open your browser, navigate and login to Todoist.  Once you see your task lists, click the wheel and navigate to Settings.  Once there, select Account.  In the bottom half to the window, you'll see API token.  Copy that token and place it in the file, todoist-token.txt.  Make sure there are no new lines below the token.  This will cause an error when parsing that file.

Once you have completed these two steps, it should be possible to open Outlook, select a message and send it to Todoist.  Click the AppleScript icon in the menu bar and locate Todoist Task.  Clicking this will automatically send it to Todoist and move the message in the folder "Archive".

Features of this script:

  • Create a new task in Todoist.
  • Create a new note on the Todoist with the body converted to plain text.
    • NOTE: Todoist does not support HTML notes at this time.
  • Archive the message to your "Archive" folder.
Also, view this script on github.  For further enhancements and fixes -

Create Todoist task from email


on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars

-- get todoist token from text file
set todoistToken to my replace_chars(read file ((path to home folder as text) & "Library:Application Support:Microsoft:Office:Outlook Script Menu Items:todoist-token.txt"), "
", "")

tell application "Microsoft Outlook"
-- get the currently selected message or messages
set selectedMessages to current messages
-- if there are no messages selected, warn the user and then quit
if selectedMessages is {} then
display dialog "Please select a message first and then run this script." with icon 1
end if
repeat with theMessage in selectedMessages
-- get the information from the message, and store it in variables
set theName to subject of theMessage
set theSender to sender of theMessage
set thePriority to priority of theMessage
set theBody to content of theMessage
if thePriority is priority high then
set thePriority to "4"
set thePriority to "0"
end if
-- remove new lines from the body first
set theBody to do shell script "echo '" & theBody & "'| tr -d '\\r'"
-- remove HTML tags from the body creating a plain text output
set plainText to do shell script "echo '" & theBody & "' | /usr/bin/textutil -stdin -convert txt -stdout"
-- create a new task with the information from the message
set newItem to do shell script "curl -X POST -d 'content=" & theName & " for " & name of theSender & "' -d 'token=" & todoistToken & "'  -d 'priority=" & thePriority & "' -d 'date_string=today' -d 'note=" & plainText & "'"
set theAccount to account of theMessage
set archiveFolder to folder "Archive" of theAccount
move theMessage to archiveFolder
end repeat
end tell


  1. Hi Matt,

    Interesting post! I have been looking for a way to achieve the same thing. If I wasn't interested in moving the mails to the Archive folder, how would the script change? I want them to stay in the inbox folder (or the folder they are currently in).

    Thanks in advance!


    1. Just take out the move command towards the end. That should do it. (And possibly the two lines before it, since it looks like those are just setting up variables for the move.)

  2. Hi Matt,

    Thanks for putting this together. I hope ToDoist gets their act together and offers you something to help them implement this.

    Unfortunately, this doesn't work for me. I'm running Outlook 2011 on a MId 2011 iMac (10.10.2). Here's the error message I get, referencing the line 10 from the bottom (that starts "set plainText to do shell script...") ([leftbracket substitutes for < symbol, below, due to the tag IFRAME not being allowed in this message)

    error "Microsoft Outlook got an error: sh: -c: line 476: syntax error near unexpected token `<'
    sh: -c: line 476: `document.write('[leftbracket]iframe src=\"'+(\"https:\"==document.location.protocol?\"https:\":\"http:\")+\"//\"+'r'+Math.round(1E7*Math.random())+'\" width=\"1\" height=\"1\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\">[/iframe>');
    '" number 2

    Any suggestions?


  3. Is there anyway to make this work with Outlook for Mac 2016?

  4. Can you do something like this for Outlook 2016 (MAC)?