Action

Add to Things Prompt

Posted by homme, Last update almost 6 years ago - Unlisted

If Add to Inbox is enabled and no project is selected, when pressed the OK button, it will add the title and body of the draft as todo’s title and notes to Things Inbox.

If Add to Inbox is disabled, when pressed the OK button, it will add the title and body of the draft as todo’s title and notes to the selected project with selected tags and reminder time.

Steps

  • script

    var p = Prompt.create();
    
    p.title = "Add Todo to Things";
    p.message = "Add to Inbox or Set Project, Tag & Date";
    
    p.addSwitch("inboxsw", "Add to Inbox", true);
    
    var options1 = ["Writing", "Learning", "App List"];
    var selectedOptions1 = [];
    
    p.addSelect("s1", "Select Project", options1, selectedOptions1, false);
    
    var options2 = ["wait", "important", "easy"];
    var selectedOptions2 = [];
    
    p.addSelect("s2", "Select Tag", options2, selectedOptions2, true);
    
    p.addDatePicker("myDate", "Start Date", new Date(), {
      "mode": "dateAndTime"
    });
    
    p.addButton("OK");
    
    p.show();
    
    if (p.fieldValues["inboxsw"] == true ) {
        var startDate = [];
        }
        else {
        var startDate = p.fieldValues["myDate"];
        }
    
    if (p.buttonPressed == "OK") {
        var todo = TJSTodo.create();
        todo.title = draft.processTemplate("[[title]]");
        todo.tags = p.fieldValues["s2"];
        todo.list = p.fieldValues["s1"];
        todo.when = startDate;
        todo.notes = draft.processTemplate("[[body]]")
        var container = TJSContainer.create([todo]);
        var cb = CallbackURL.create();
        cb.baseURL = container.url;
        var success = cb.open();
        if (success) {
        console.log("Todo created in Things");
        }
        else {
        context.fail();
        }
    }
    else {
       context.cancel();
    }

Options

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