Action

Add Script to Things

Posted by @craigmcclellan, Last update almost 6 years ago

After a Script is started in Drafts using Tim Nahumck’s New Code Draft action from his action scripting group, this Script will take the URL of the Draft and make a task in Things reminding you to work on this script and linking you back to it.

Steps

  • script

    // Add Script to Things
    
    var draftURL = draft.permalink;
    var codeTitle = draft.processTemplate("[[title]]");
    var scriptTitle = codeTitle.slice(3);
    
    // Prompt to either write a new script or update an existing one with a new feature.
    var p = Prompt.create();
    p.title = "Action Selector";
    p.message = "How would you like to send this script to Things?";
    p.addButton("Create New Script");
    p.addButton("Update Existing Script")
    p.show();
    
    var input = p.buttonPressed;
    
    var todo = TJSTodo.create();
    todo.list = "Drafts Actions";
    
    
    // If new script, just create a task with the title of the script and a link. If not, prompt for a feature you'd like to add which will be added to notes.
    if (input == "Create New Script") {
      todo.title = scriptTitle;
     }
    else {
    	todo.title = "Update " + scriptTitle;
    	var q = Prompt.create();
    	q.title = "Feature";
    	q.message = "What feature would you like to add to the script?";
    	q.addTextView("feature", "Feature", "");
    	q.addButton("Done");
    	q.show();
    	var feature = q.fieldValues["feature"];
    }
    
    // Add link and feature (if created) to task Notes
    
    todo.notes = feature + "\n" + "\n" + draftURL;
    
    // create a container to handle creation of Things URL
    
    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("Script Added to Things");
    }
    else {
    	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.