Action

Reminder with options

Posted by agiletortoise, Last update over 1 year ago

Prompt to create a reminder in the Reminders app with options to set due date, priority, and select the target list. The first line of the draft will default to the task value, remaining body will be the suggested notes.

The “Due” date field supports natural language parsing of dates, so things like “2pm Friday”, or “next Wednesday” work for specifying due date.

Steps

  • script

    let title = draft.processTemplate("[[title]]");
    let notes = draft.processTemplate("[[body]]");
    
    let f = () => {
    	// get lists
    	let lists = ReminderList.getAllReminderLists();
    	let listNames = lists.map(x => x.title);
    	let defaultList = ReminderList.default();
    	let defaultIndex = listNames.findIndex(x => x == defaultList.title);
    	
    	let p = Prompt.create();
    	p.title = "Create Reminder"
    	p.message = "Select options for new task below.";
    	
    	p.addTextField("title", "Title", title, {});
    	p.addTextField("dueDate", "Due", "", {
    		"placeholder": "optional date"
    	});
    	p.addPicker("priority", "Priority", [["None", "Low", "Medium", "High"]], [0]);
    	p.addTextView("notes", "Notes", notes, {});
    	p.addPicker("list", "List", [listNames], [defaultIndex]);
    	
    	p.addButton("Create Reminder");
    	if (!p.show()) {
    		return 1;
    	}
    	
    	let selectedListIndex = p.fieldValues["list"];
    	let list = lists[selectedListIndex];
    	let rem = list.createReminder();
    	
    	rem.title = p.fieldValues["title"];
    	rem.notes = p.fieldValues["notes"];
    	let dStr = p.fieldValues["dueDate"];
    	if (dStr && dStr.length > 0) {
    		rem.dueDate = Date.parse(dStr);
    	}
    	let priority = p.fieldValues["priority"];
    	if (priority == 1) {
    		rem.priority = 9;
    	}
    	else if (priority == 2) {
    		rem.priority = 5;
    	}
    	else if (priority == 3) {
    		rem.priority = 9;
    	}
    	else {
    		rem.priority = 0;
    	}
    	if (rem.update()) {
    		console.log("Reminder created");
    	}
    	else {
    		console.log("Error creating reminder");
    		return -1;
    	}
    	return 0;
    }
    
    let result = f();
    switch (result) {
    	case -1: context.fail(); break;
    	case 1: context.cancel(); break
    }

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.