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.

The second version works on my device.

The code looks fine to me. Though it might be a good idea to define a function for the date and alarm calculation and maybe set some constants

Did you know that you could define a drafts action with functions, variables and constants add add them as a post action to use them in the follow up scripts.

I am still playing with this idea and am not as happy with the editing experience and the keyboard of the script editor. A nice way would to use drafts or another code editor with javascript highlighting and import / export the scripts after editing them.

You might also be interested in the require(script) function.

Yes totally useful and better to manage.

! Thats what I was missing.

I have to get a deeper dive into your script reference