Reminders Script

Hi. I’m a novice to JS but I wrote this script which might help someone who wants to get going with Reminders integration. This will create a reminder with a due date and an alarm at 12:30 - either today or tomorrow depending on the current time. Not sure it’ll be useful to anyone but thought I’d post it.
-Lyle

// from the draft var alerttime = "12:30" var title = draft.content

// default to today but if it’s after that time, use tomorrow
var today = new Date();
var tomorrow = new Date(today.getTime() + (24 * 60 * 60 * 1000));
var whichday=today;
var now = today.getHours()*100+today.getMinutes();
if ( now > alerttime.replace(":","")) { var whichday=tomorrow;}

// date and time for the reminder
var datestring=whichday.getFullYear()+"/"+(whichday.getMonth()+1)+"/"+whichday.getDate()+" "+alerttime;
var due=new Date (datestring);

// add the reminder
var list = ReminderList.findOrCreate(“TESTING”);
var rem = list.createReminder();
rem.title = title;
rem.dueDate = due;
rem.addAlarm(Alarm.alarmWithDate(due));
rem.update();

3 Likes

Hi, Lyle!

I tried it but it gives me an error.

Try this amended version. The one above had a couple of variables commented out and the reminder list name was using smart quotes instead of dumb quotes.

// from the draft 
var alerttime = "12:30";
var title = "title goes here";
// default to today but if it’s after that time, use tomorrow
var today = new Date();
var tomorrow = new Date(today.getTime() + (24 * 60 * 60 * 1000));
var whichday=today;
var now = today.getHours()*100+today.getMinutes();
if ( now > alerttime.replace(":","")) { var whichday=tomorrow;}
// date and time for the reminder
var datestring=whichday.getFullYear()+"/"+(whichday.getMonth()+1)+"/"+whichday.getDate()+" "+alerttime;
var due=new Date (datestring);
// add the reminder
var list = ReminderList.findOrCreate("TESTING");
var rem = list.createReminder();
rem.title = title;
rem.dueDate = due;
rem.addAlarm(Alarm.alarmWithDate(due));
rem.update();

Wouldn’t there be a way to include the date, time of the reminder in the Draft itself? Along with the list and the actual reminder?

#house
Fix the gutters.
remind 3:00PM 7/1/2020

Yes. Instead of the date being set purely within the script you would read it in from the draft and parse it to construct your date object.

You can always format the data however you like than slice, dice and parse whatever you want. The above was just an example from @lyle.