Action

Remind Me of… Draft

Posted by @nahumck, Last update almost 5 years ago - Unlisted

Creates a reminder with a link back to the draft, setting a due date and time for the reminder.

Note: This can use the following apps: Reminders, GoodTask, Things, Todoist, and OmniFocus.. Disable the Reminders script step and enable the task manager of choice. (swipe to the left to bring up the option to disable) Format of the output is unique to each task manager.

Steps

  • script

    // check to see if draft is blank
    var content = draft.content;
    var check = content.length;
    
    if (content.length == 0) {
    	alert("Draft is blank");
    	context.cancel("Draft was blank");
    }
    
    // Get link to draft
    var url = draft.permalink;
    
    // Prompt for date with toggle for reminder
    var p = Prompt.create();
    p.title = "Select Date";
    p.addTextField("title", "Title", draft.title);
    p.addDatePicker("due","Select Due Date", new Date(),{"mode":"dateAndTime","minuteInterval":5});
    p.addSwitch("switch","Add an alert?", false);
    p.addButton("Create Task");
    var con = p.show();
    
    var title =  p.fieldValues["title"];
    var due = p.fieldValues["due"];
    var check = p.fieldValues["switch"];
  • script

    //Create Task in Reminders
    
    var list = ReminderList.findOrCreate("Inbox")
    var alarm = Alarm.alarmWithDate(due);
    var reminder = list.createReminder();
    reminder.title = title;
    reminder.dueDate = due;
    if(check == false){
      reminder.dueDateIncludesTime = true
      //alert(check)
    }
    else {
      reminder.dueDateIncludesTime = false
      reminder.addAlarm(alarm)
    }
    //reminder.url = url;
    reminder.notes = url;
    reminder.update();
  • script

    // Create Task in GoodTask
    
    if (con) {
    	// 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/";
    	var cb = CallbackURL.create();
    	cb.baseURL = baseURL;
    	cb.addParameter("title", title);
    	cb.addParameter("list", "Inbox");
    	cb.addParameter("due", due.toString("yyyy-MM-dd HH:mm"));
    	cb.addParameter("alarm", 1);
    	cb.addParameter("url", url);
    	// open and wait for result
    	var success = cb.open();
    	if (success) {
    		console.log("Event created");
    	}
    	else { // something went wrong or was cancelled
    	  	console.log(cb.status);
    	  	if (cb.status == "cancel") {
    			context.cancel();
    		}
    		else {
    			context.fail();
    		}
    	}
    }
    else {
    	context.cancel();
    }
  • script

    // Create Task in Things
    if (con) {
    	var todo = TJSTodo.create();
    	todo.title = title;
    	todo.when = due;
    	todo.notes = url;
    	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();
    	}
    }
    else {
    	context.cancel();
    }
  • script

    // Add Task in Todoist
    
    // Create Todoist credentials
    var credential = Credential.create("Todoist", "Todoist API");
    credential.addTextField("token", "Token");
    credential.authorize();
    
    // Create variables for quick add
    var text = "["+title+"]("+url+")";
    var note = "";
    var reminder = due.toString("dd/MM/yyyy HH:mm")
    
    // Create Task in Todoist
    let todoist = Todoist.create();
    let task = todoist.quickAdd(text, note, reminder);
  • script

    // Create Task in OmniFocus
    if (con) {
    	var cb = CallbackURL.create();
    	cb.baseURL = 'omnifocus://x-callback-url/add';
    	cb.addParameter('name',title);
    	cb.addParameter('due',due);
    	cb.addParameter('note',url);
    	var success = cb.open();
    	if (success) {
    		console.log("Task created in OmniFocus");
    	}
    	else {
    		context.fail();
    	}
    }
    else {
    	context.cancel();
    }
  • script

    if (con) {
    	var cb = CallbackURL.create();
    	cb.baseURL = 'fantastical2://x-callback-url/parse/';
    	cb.addParameter("title", title);
    	cb.addParameter("due", due.toString("yyyy-MM-dd HH:mm"));
    	cb.addParameter("reminder", 1);
    	cb.addParameter("add", 1);
    	cb.addParameter("url", url);
    	var success = cb.open();
    	if (success) {
    		console.log("Task created in Fantastical");
    	}
    	else {
    		context.fail();
    	}
    }
    else {
    	context.cancel();
    }

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.