Action

Reminders from lines in Draft with Options

Posted by @FlohGro, Last update 5 months ago

UPDATES

5 months ago

bugfixes

show all updates...

5 months ago

bugfixes

almost 2 years ago

ignore empty lines

almost 2 years ago

added missing space in success message

created by @FlohGro / more on my Blog

adapted from this action: https://actions.getdrafts.com/a/1Rr

Prompt to create a reminder in the Reminders app with options to set due date, priority, and select the target list.
Each line in the Draft will be considered as task (you can edit them in the prompt)

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


If you find this useful and want to support me you can

Buy Me A Coffee

Steps

  • script

    let f = () => {
    	// check if draft is empty
    	if(draft.content.length == 0){
    	return 1;
    	app.displayInfoMessage("draft is empty")
    	}
    	//get array of tasks (each line)
    	let tasks = draft.content.split("\n");
    	// 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 createdRemCount = 0
       for(task of tasks){
       if(task == ""){
       continue;
       }
    	let p = Prompt.create();
    	p.title = "Create Reminder"
    	p.message = "Select options for new task below.";
    	
    	p.addTextField("title", "Title", task, {});
    	p.addTextField("dueDate", "Due", "", {
    		"placeholder": "optional date"
    	});
    	p.addPicker("priority", "Priority", [["None", "Low", "Medium", "High"]], [0]);
    	p.addTextView("notes", "Notes", "", {});
    	p.addPicker("list", "List", [listNames], [defaultIndex]);
    	
    	p.addButton("Create Reminder");
    	if (!p.show()) {
    		return 1;
    	   app.displayInfoMessage("aborted by user")
    	}
    	
    	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 = 1;
    	}
    	else {
    		rem.priority = 0;
    	}
    	if (rem.update()) {
    		console.log("Reminder created");
    	}
    	else {
    		console.log("Error creating reminder");
    		return -1;
    	}
    	createdRemCount++;
    	}
    
    	return createdRemCount;
    }
    
    let result = f();
    switch (result) {
    	case -1: context.fail(); break;
    	case 0: context.cancel(); break;
    	default: app.displaySuccessMessage("created " + result + " reminder(s)")
    }

Options

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