Action

Reminder with Options

Posted by agiletortoise, Last update about 17 hours ago

UPDATES

about 17 hours ago

Also add alarm if a due date is set

show all updates...

about 17 hours ago

Also add alarm if a due date is set

over 3 years ago

Fixed issue setting “High” priority.

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. If a due date is set, and alarm will also be created to trigger and alert.

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) {
    		let d = Date.parse(dStr)
    		rem.dueDate = d
    		let a = Alarm.alarmWithDate(d)
    		rem.addAlarm(a)
    	}
    	let priority = p.fieldValues["priority"]
    	if (priority == 1) {
    		rem.priority = 9
    	}
    	else if (priority == 2) {
    		rem.priority = 5
    	}
    	else if (priority == 3) {
    		rem.priority = 1
    	}
    	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.