Action

Pre-Travel List → Things

Posted by @nahumck, Last update almost 6 years ago

Create a pre-defined packing list in Things. You will first be prompted for a Trip Name, Note, and a date of when the packing needs to be completed. Sends a project to Things, broken up by areas. Uses a modified version of Send to Things by Tyler Eich.

Steps

  • script

    var p = Prompt.create();
    p.title = "Trip Name & Desc";
    p.addTextField("title", "Title", "");
    p.addTextView("note", "Description", "", {"height":40});
    p.addDatePicker("deadline","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 when = new Date();
    when = when.toString("yyyy-MM-dd");
    var deadline = p.fieldValues["deadline"];
    deadline = deadline.toString("yyyy-MM-dd");
    
    if (con) {
    	draft.setTemplateTag("title", title);
    	draft.setTemplateTag("note", note);
    	draft.setTemplateTag("deadline", deadline);
    	draft.setTemplateTag("when", when);
    }
    else {
    	context.cancel();
    }
  • clipboard

    template
    # [[title]] Packing List
    > [[note]]
    #travel
    :[[when]]
    ![[deadline]]
    
    ## 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
  • script

    var d = Draft.create();
    d.content = app.getClipboard();
    /*
      Send to Things (mod)
    */
    
    const getTargetItem = state => state.todo || state.project
    
    const parsers = [
    	{
    		// Project
    		pattern: /^# /g,
    		transform(state, input) {
    			const project = TJSProject.create()
    			project.title = input
    
    			if (state.list) {
    				project.area = state.list
    			}
    
    			state.items.push(project)
    			state.project = project
    			// state.list = null
    			state.todo = null
    		}
    	},
    	{
    		// Heading
    		pattern: /^## /g,
    		transform(state, input) {
    			const heading = TJSHeading.create()
    			heading.title = input
    
    			if (state.project) {
    				state.project.addHeading(heading)
    			}
    		}
    	},
    	{
    		// Checklist item
    		pattern: /^- /g,
    		transform(state, input) {
    			const checklistItem = TJSChecklistItem.create()
    			checklistItem.title = input
    
    			if (state.todo) {
    				state.todo.addChecklistItem(checklistItem)
    			}
    		}
    	},
    	{
    		// Note
    		pattern: /^> ?/g,
    		transform(state, input) {
    			const targetItem = getTargetItem(state)
    
    			if (targetItem) {
    				if (!targetItem.notes) {
    					targetItem.notes = input
    				} else {
    					targetItem.notes += `\n${input}`
    				}
    			}
    		}
    	},
    	{
    		// Tag
    		pattern: /^#/g,
    		transform(state, input) {
    			const targetItem = getTargetItem(state)
    
    			if (targetItem) {
    				if (!Array.isArray(targetItem.tags)) {
    					targetItem.tags = [input]
    				} else {
    					targetItem.tags.push(input)
    				}
    			}
    		}
    	},
    	{
    		// List
    		pattern: /^@ ?/g,
    		transform(state, input) {
    			state.list = input
    		}
    	},
    	{
    		// When
    		pattern: /^: ?/g,
    		transform(state, input) {
    			const targetItem = getTargetItem(state)
    
    			if (targetItem) {
    				targetItem.when = input
    			}
    		}
    	},
    	{
    		// Deadline
    		pattern: /^! ?/g,
    		transform(state, input) {
    			const targetItem = getTargetItem(state)
    
    			if (targetItem) {
    				targetItem.deadline = input
    			}
    		}
    	},
    	{
    		// Comments
    		pattern: /^\/\//g,
    		transform(state, input) {
    			// These are comments, so this transform does nothing
    		}
    	},
    	{
    		// Todo (matches everything else)
    		pattern: /^/g,
    		transform(state, input) {
    			const todo = TJSTodo.create()
    			todo.title = input
    
    			if (state.list) {
    				todo.list = state.list
    			}
    
    			if (state.project) {
    				state.project.addTodo(todo)
    			} else {
    				state.items.push(todo)
    			}
    
    			state.todo = todo
    		}
    	}
    ]
    
    // const projectPattern = /^# /g
    // const subheadingPattern = /^## /g
    // const checklistItemPattern = /^- /g
    // const notePattern = /^> ?/g
    
    // const listPattern = /^@ ?/g
    // const tagPattern = /^#[^\s]|$ ?/g
    // const whenPattern = /^: ?/g
    // const deadlinePattern = /^! ?/g
    
    const lines = d.content.split("\n").filter(line => line.length)
    
    
    
    const state = lines.reduce((state, line) => {
    	for (var {pattern, transform} of parsers) {
    		if (pattern.test(line)) {
    			const input = line.replace(pattern, "")
    			transform(state, input)
    			break
    		}
    	}
    	
    	return state
    },
    {
      project: null,
      todo: null,
      list: null,
      items: []
    })
    
    
    const {url} = TJSContainer.create(state.items)
    
    console.log(url)
    
    const cb = CallbackURL.create()
    cb.baseURL = url
    
    
    if (cb.open()) {
    	console.log("Todos created in Things")
    } else {
    	context.fail()
    }
    // Clear Clipboard
    app.setClipboard("");
    app.displayInfoMessage("Clipboard Cleared");

Options

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