Action

Tasks2Things

Posted by @andreaslezgus, Last update over 4 years ago
  1. Send all marked Task in a draft to Things
  2. Put a backward link in all Things Tasks
  3. Mark every draft Tasks as completed
  4. Archive the draft

Use case:
Daily or weekly shutdown routine as a mind sweep in drafts to write down all stuff thats in your head. Mark those things as tasks, you will operate later on in your task manager.

By Andreas Lezgus - @andreaslezgus
https://www.lezgus.de/start.html

Steps

  • script

    const taskPrefix = "- [ ] ";
    const checkPrefix = "- [x] ";
    
    // check to see if draft is blank
    var content = editor.getText();
    var check = content.length;
    var taskList = "";
    var draftURL = draft.permalink;
    
    if (content.length == 0) {
    	alert("Draft is blank");
    	context.cancel("Draft was blank");
    }
    
    // Call API for each line in a draft
    // split draft and loop over lines
    var lines = content.split("\n");
    
    var thingsTask = Array();
    
    
    for (var line of lines) {
    	if (line.startsWith(taskPrefix)) {
    		task = line.split(taskPrefix)[1];
    		temp = TJSTodo.create();
    		temp.title = task;
    		temp.notes = draftURL;
    		thingsTask.push(temp);
    		taskList += task + "\n";
    		content = content.replace(line + "\n", "");
        
    	}
    }
    
    
    if (thingsTask.length) {
    	var container = TJSContainer.create(thingsTask);
    	var cb = CallbackURL.create();
    	cb.baseURL = container.url;
    	
    	if (cb.open()) {
    	console.log("Todos created in Things");
    	
    	
    }
    else {
    	console.fail();
    }
    	
    }
    
    for (var line of lines) {
    	if (line.startsWith(taskPrefix)) {
    		
        // do the replacement...
    draft.content = draft.content.replace(taskPrefix, checkPrefix);
    draft.update();
    	}
    }
    
    	

Options

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