Drafts Action Directory

Pre-Travel List

Posted by @nahumck, Last updated: 2018-06-22 21:12:18 UTC

Create a pre-defined packing list in Drafts, prompting for a Trip Name, Note, and a date of when the packing needs to be completed. Sends a task to Things, with the permalink to the draft appended to the note.

Note: This can also work for GoodTask. Simply disable the Things script steps and enable the GoodTask steps.

Install

Steps

  • script

    //Setup for Things
    
    var when = new Date();
    var p = Prompt.create();
    p.title = "Trip Name & Desc";
    p.addTextField("title", "Title", "");
    p.addTextView("note", "Description", "", {"height":40});
    p.addDatePicker("when","When do you need to pack by?", new Date(), {"mode":"date"});
    p.addButton("Create List");
    var con = p.show();
    
    var title =  p.fieldValues["title"];
    var note = p.fieldValues["note"];
    var deadline = p.fieldValues["when"];
    
    if (con) {
    	draft.setTemplateTag("title", title);
    	draft.setTemplateTag("note",note);
    }
    else {
    	context.cancel();
    }
  • script (disabled)

    // Setup for GoodTask
    
    var when = new Date();
    var p = Prompt.create();
    p.title = "Trip Name & Desc";
    p.addTextField("title", "Title", "");
    p.addTextView("note", "Description", "", {"height":40});
    p.addDatePicker("when","When do you need to pack by?", new Date(), {"mode":"dateAndTime"});
    p.addButton("Create List");
    var con = p.show();
    
    var title =  p.fieldValues["title"];
    var note = p.fieldValues["note"];
    var deadline = p.fieldValues["when"];
    deadline = deadline.toString("yyyy-MM-dd HH:mm");
    
    if (con) {
    	draft.setTemplateTag("title", title);
    	draft.setTemplateTag("note",note);
    }
    else {
    	context.cancel();
    }
  • clipboard

    template
    # [[title]] Packing List
    > [[note]]
    
    ## Toiletries
    - [ ] Deodorant
    - [ ] Toothbrush
    - [ ] Toothpaste
    - [ ] Hair Products
    - [ ] Nose Spray & Strips
    - [ ] Medicine
    - [ ] Shaving Kit
    - [ ] Sunscreen
    - [ ] Bug Spray 
    - [ ] Q-Tips
    
    ## Personal Items
    - [ ] Book
    - [ ] Earphones
    - [ ] Earplugs
    - [ ] Tissues
    - [ ] Cash
    - [ ] Electronics and Chargers 
    - [ ] Camera Bag/Equipment
    - [ ] Itinerary
    - [ ] Boarding Passes
    - [ ] Passport
    
    ## Clothing
    - [ ] Socks
    - [ ] Underwear
    - [ ] Pants/belts/shorts
    - [ ] Shirts
    - [ ] PJ's
    - [ ] Shoes/boots/sandals
    - [ ] Sunglasses
    - [ ] Jacket (Rain at Min)
    - [ ] Other Outerwear(gloves, Hat, Etc)
    - [ ] Bathing Suit
    
    ## Tasks Before Leaving
    - [ ] Stop Mail
    - [ ] Clear Fridge
    - [ ] Turn off ice maker
    - [ ] Print Tickets
    - [ ] Parking Coupon
    - [ ] Check-in for Flight
    - [ ] Thermostat
    - [ ] Take Out Garbage
    - [ ] Lock House
    - [ ] Arm Alarm/Camera System
    
    ## Miscellaneous
    - [ ] 
    
    ----
    ## Completed
  • script

    var d = Draft.create();
    d.content = app.getClipboard();
    d.update();
    var url = d.permalink;
    app.setClipboard("");
    
    var todo = TJSTodo.create();
    todo.title = "Pack for "+title;
    todo.when = when;
    todo.deadline = deadline;
    todo.notes = note+"\n"+url;
    todo.list = ["Personal"];
    todo.tags = ["Travel"];
    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();
    }
    editor.activate(d);
  • script (disabled)

    // Create List in GoodTask
    
    var d = Draft.create();
    d.content = app.getClipboard();
    d.update();
    var url = d.permalink;
    app.setClipboard("");
    // goodtask3://add?title=[prompt:Title]&list=[prompt:List Name]&due=[prompt:Due Date]&dueAfter=[prompt-num:Due after]&alarm=[prompt-num:Alarm]&priority=[prompt-num:Priority]&url=[prompt:URL]&notes=[prompt:Notes] 
    
    const baseURL = "goodtask3://x-callback-url/add?";
    
    // create and configure callback object
    var cb = CallbackURL.create();
    cb.baseURL = baseURL;
    cb.addParameter("title", "Pack for "+title);
    cb.addParameter("list", "Personal");
    cb.addParameter("due", deadline);
    cb.addParameter("alarm", 1);
    cb.addParameter("url", url);
    cb.addParameter("notes", note);
    // open and wait for result
    var success = cb.open();
    if (success) {
    	console.log("Task created");
    }
    else { // something went wrong or was cancelled
    	 console.log(cb.status);
    	 if (cb.status == "cancel") {
    		context.cancel();
    	}
    	else {
    		context.fail();
    	}
    }
    editor.activate(d);

Comments

Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.