Action

Todos in Things

Posted by agiletortoise, Last update over 1 year ago - Unlisted

UPDATES

over 1 year ago

Now supports targeting a specific list by including “# List Name” as the first line of the draft.

Send each line of the draft to Things as a separate todo.

Defaults to creating todos in the Things Inbox. To target a specific list, use “# List Name” in the first line of the draft. The list name must match an existing list in Things, or the todos will be created in the Inbox.

For more information on working with Things and Drafts, visit the integration guide.

Steps

  • script

    /*
      Send each line of a draft to things as a todo
      Check first line for "#" at beginning, and use that as list name if present
    */
    const lines = draft.content.split("\n")
    let todos = []
    let list = "Inbox"
    
    if (lines[0].startsWith("#")) {
    	let newList = lines.shift() // remove first line
    	newList = newList.replaceAll("#", "") // remove "#"
    	newList = newList.trim()
    	list = newList
    }
    
    // loop over lines, adding non-blank lines as todos
    for (line of lines) {
    	let trimmedLine = line.trim() // remove whitespace
    	if (trimmedLine.length == 0) { // skip blank lines
    		continue
    	}
    	let todo = TJSTodo.create()
    	todo.title = trimmedLine
    	todo.list = list
    	todos.push(todo)
    }
    
    if (todos.length > 0) {
    	// create Things object to create URL
    	const container = TJSContainer.create(todos)
    	var cb = CallbackURL.create()
    	cb.baseURL = container.url
    
    	if (cb.open()) {
    		console.log("Todos created in Things")
    	}
    	else {
    		console.fail()
    	}
    }
    else { // no todos to create
    	alert("No todos found")
    	context.fail()
    }

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.