Description[]
The script will create specific to-dos in your calendar on a specified date, effectively giving a to-do a "start date".
At the daily time, the script will harvest all the events in a Google Calendar called HabiticaReminders scheduled for that day. It will then add them to Habitica as medium priority to-do's. To schedule a future task, simply select the correct day in Google Calendar and add an event with the to-do text as a title. Make sure you add it to HabiticaReminders and not your default calendar. A suggestion is to hide the calendar the rest of the time, so it doesn't clutter the calendar interface.
Note: The default timezone for Google Scripts is America/Los_Angeles (Pacific time). If your calendar is in a different timezone, this will not be taken into account. The easiest way to address this is to add an app manifest and change the timezone to one of the valid values that corresponds to the timezone of your calendar.
Installation[]
- Create a new calendar in your personal Google Calendar name HabiticaReminders.
- Go to script.google.com. If this is your first script, this will automatically create a new Google script for you and open an editor for it. Otherwise, edit an existing project by clicking the pencil icon next to it, or create another.
- Paste the code snippet below into the editor, replacing the spaces marked #HabiticaUserID# and #HabiticaAPIToken# with Habitica User ID and API Token (leave the quotes). These can be found under the API tab in your Habitica settings.
function scheduleToDos() { var habId = "#HabiticaUserID#"; var habToken = "#HabiticaAPIToken#"; var now = new Date(); var events = CalendarApp.getCalendarsByName("HabiticaReminders")[0].getEventsForDay(now); var paramsTemplate = { "method" : "post", "headers" : { "x-api-user" : habId, "x-api-key" : habToken } } for (i = 0; i < events.length; i++) { var params = paramsTemplate; params["payload"] = { "text" : events[i].getTitle(), "type" : "todo", "notes" : events[i].getDescription(), "priority" : "1.5" } UrlFetchApp.fetch("https://habitica.com/api/v3/tasks/user", params) } }
- Under Edit, select Current project's triggers. Then add a trigger that runs scheduleToDos Time-driven on a Day timer. Suggested time is after your cron, early in the morning, like 3-4am.
- Save and you're done!