Todoist

In general, using templates or recurring tasks fulfill most use cases for adding routine tasks to Todoist. Occasionally, there are a set of tasks which could use some more complex logic around the text of the task, calculating due dates, etc. On the Mac, I usually turn to AppleScript.

AppleScript

So, we start with a very basic Apple Script function that can be called from within your main script.

on addItem(args)
	
   set defaultArgs to {priority:1, schedule:""}
	
   set args to args & defaultArgs
	
   set content to content of args
	
   set labels to labels of args
	
   set priority to priority of args
	
   set schedule to schedule of args
	
	

   set token to "GET FROM YOUR ACCOUNT"
	
   set myUUID to do shell script "uuidgen"
	
   set tempUUID to do shell script "uuidgen"
	

   set due to "{\"string\":\"" & schedule & "\"}"
   set tdCommand to "[{\"type\": \"item_add\", 
     \"uuid\": \"" & myUUID & "\", 
     \"temp_id\":\"" & tempUUID & "\", 
     \"args\": {
         \"content\": \"" & content & "\", 
         \"due\":" & due & ", 
         \"priority\":" & priority & ", 
         \"labels\":" & labels & "}}]"
	

   set curlCmd to "curl    https://api.todoist.com/sync/v8/sync -d token=" & token & " -d commands='" & tdCommand & "'"
	
	
   do shell script curlCmd

end addItem

This function depends on 2 external programs:

  • curl
  • uuiden

Once we have this function, it can then be used inside of a script, for example:

display dialog "Please enter some text to prefix the task :" 
set entryPrefix to text returned of result

set labelIds to "[1111111111, 1111111112]"

addItem({content:"(" & entryPrefix & ") " & "Task text", priority:2, labels:labelIds})