Drafts Action Directory

Add Single Thing

Posted by @nahumck, Last updated: 2018-05-27 09:31:29 UTC

Send a single task with a note to a specific area in a prompt.

Install

Steps

  • script

    // Single Task script
    
    // Prompt
    /* --------------------- */
    var areas = ["Personal", "Household", "Family", "Finance", "Errands"];
    
    var p = Prompt.create();
    p.title = "Task to Things";
    p.addTextField("task", "Task", "");
    p.addTextView("note", "Note", "", {"height": 50});
    p.addSelect("area", "Area", areas, [""], false);
    p.addDatePicker("when","When", new Date(), {"mode":"date"});
    p.addButton("Send to Things");
    var con = p.show();
    
    var task = p.fieldValues["task"];
    var note = p.fieldValues["note"];
    var area = p.fieldValues["area"];
    var when = p.fieldValues["when"];
    
    if (p.buttonPressed == "Send to Things") {
    	var todo = TJSTodo.create();
    	todo.title = task;
    	todo.when = when;
    	todo.notes = note;
    	todo.list = area;
    	todo.tags = ["Singles"];
    	var container = TJSContainer.create([todo]);
    	// Use CallbackURL object to open URL in Things.
    	var cb = CallbackURL.create();
    	cb.baseURL = container.url;
    	var success = cb.open();
    	if (success) {
    		console.log("Task created in 	Things");
    	}
    	else {
    		context.fail();
    	}
    }
    else {
      context.cancel();
    }
Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.