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();
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();
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.