MilkScript

Automate tasks with MilkScript.

menu

Task

Represents a task.


addNote(content)

Adds a new note to the task.

Parameters

content

The note content. Cannot be empty or contain only whitespace.

Return value

The updated Task.

Example

// Adds a new task, then adds a note to the task.
rtm.addTask('Buy gift for Alice')
   .addNote('Check out gift cards and subscription boxes.');

addSubtask(name, parse)

Adds a new subtask to the task.

Parameters

name

The name of the new subtask. Cannot be empty or contain only whitespace.

parseOptional

true to use Smart Add to process the subtask name, false otherwise.

Return value

The newly added subTask.

Example

// Adds a new task, then adds a couple of subtasks to the task.
const task = rtm.addTask('Organize Alice\'s birthday party');
task.addSubtask('Send invitations');
task.addSubtask('Book the clown ^today !1', true);

addTags(...tags)

Adds the given tags to the task.

Parameters

...tags

A variable number of tags to add. Tags cannot be empty or contain only whitespace. Every tag is lowercased and stripped of unsupported characters.

Return value

The updated Task.

Example

// Adds a new task, and then tags the task with 'errand' and 'groceries'.
const task = rtm.addTask('Pick up the milk');
task.addTags('errand', 'groceries');

complete()

Marks the task and all its subtasks complete. If this is a recurring task, a new task instance will be generated on completion.

Return value

The completed Task.

Example

// Completes all tasks in "Project Moo" list.
const tasks = rtm.getTasks('list:"Project Moo"');
tasks.forEach(task => task.complete());
console.log('Completed %d task(s) in "Project Moo" list.', tasks.length);

decreasePriority()

Decreases the task priority. Does nothing if the task has no priority.

Return value

The updated Task.

Example

// Decreases priority of all tasks tagged with "monkey_business".
const tasks = rtm.getTasks('tag:monkey_business');
tasks.forEach(task => task.decreasePriority());
console.log('Decreased priority of %d task(s) tagged with "monkey_business".',
  tasks.length);

delete(stopRecurring)

Deletes the task.

Parameters

stopRecurringOptional

true to stop the deleted task from recurring, false otherwise. Does nothing if this is not a recurring task. If this is a recurring task and stopRepeating is not provided or set to false, a new task instance will be generated on deletion.

Return value

undefined

Example

// Searches tasks named "Throw a wrench in the works" and deletes all of them.
const tasks = rtm.getTasks('name:"Throw a wrench in the works"');
tasks.forEach(task => task.delete());
console.log("Deleted %d task(s)", tasks.length);

getCompletedDate()

Gets the date and time the task was completed.

Return value

The date the task was completed, or null if the task is incomplete.

Example

// Outputs the completed date and time of all the tasks completed in
// the past week.
const tasks = rtm.getTasks('completedWithin:"1 week of today"');
tasks.sort((a, b) => a.getCompletedDate() - b.getCompletedDate());
tasks.forEach(task =>
  console.log("%s - %s", task.getName(), task.getCompletedDate()));

getCreatedDate()

Gets the date the task was created.

Return value

Date

Example

// Outputs the created date and time of all the tasks completed today.
const tasks = rtm.getTasks('completed:today');
tasks.sort((a, b) => a.getCreatedDate() - b.getCreatedDate());
tasks.forEach(task =>
  console.log("%s - %s", task.getName(), task.getCreatedDate()));

getDueDate()

Gets the date and time at which this task is due.

If hasDueTime is true then the due date indicates the instant in time at which the task is due.

If hasDueTime is false then the due date indicates midnight at the beginning of the day when the task is due.

Return value

The Date when the task is due, or null if the task has no due date.

Example

// Outputs the due date of all the tasks in "High Priority" list.
const tasks = rtm.getTasks('list:"High Priority"');
tasks.sort((a, b) => a.getDueDate() - b.getDueDate());
tasks.forEach(task =>
  console.log("%s - %s", task.getName(), task.getDueDate()));

getEstimate()

Gets the estimate of the task.

Return value

The Estimate of the task, or null if the task has no estimate.

Example

// Outputs the estimate of all the tasks in "Monkey around" list.
const tasks = rtm.getTasks('list:"Monkey around"');
tasks.sort((a, b) => a.getName().localeCompare(b.getName()));
tasks.forEach(task =>
  console.log("%s - %s", task.getName(), task.getEstimate()));

getId()

Gets the ID of the task.

Return value

string


getList()

Gets the list that contains this task.

Return value

List

Example

// Outputs the lists of all tasks added today.
const tasks = rtm.getTasks('added:today');
tasks.sort((a, b) => a.getName().localeCompare(b.getName()));
tasks.forEach(task =>
  console.log("%s - %s", task.getName(), task.getList().getName()));

getLocation()

Gets the location of the task.

Return value

The Location of the task, or null if the task has no location.

Example

// Outputs the locations of all tasks added in the past week.
const tasks = rtm.getTasks('addedWithin:"1 week of today"');
tasks.sort((a, b) => a.getName().localeCompare(b.getName()));
tasks.forEach(task => {
  const location = task.getLocation();
  console.log("%s - %s",
    task.getName(), location != null ? location.getName() : 'none');
});

getModifiedDate()

Gets the date the task was last modified.

Return value

Date

Example

// Outputs the modification time of all tasks updated today.
const tasks = rtm.getTasks('updated:today AND NOT added:today');
tasks.sort((a, b) => a.getModifiedDate() - b.getModifiedDate());
tasks.forEach(task =>
  console.log("%s - %s", task.getName(), task.getModifiedDate()));

getName()

Gets the name of the task.

Return value

The name of the Task.

Example

// Outputs all tasks completed today.
const tasks = rtm.getTasks('completed:today');
tasks.sort((a, b) => a.getCompletedDate() - b.getCompletedDate());
tasks.forEach(task =>
  console.log("%s - %s", task.getName(), task.getCompletedDate()));

getNotes()

Gets the notes of the task.

Return value

The list of Notes.

Example

// Outputs the total number of notes for tasks added in the past week.
const tasks = rtm.getTasks('addedWithin:"1 week of today"');
let total = 0;
tasks.forEach(task => total += task.getNotes().length);
console.log("Total notes in the past week: %d", total);

getParent()

Gets the parent of the task.

Return value

The parent Task, or null if this task has no parent.

Example

// Outputs subtasks and their parent tasks in "Someday" list.
const subtasks =
  rtm.getTasks('list:Someday AND status:incomplete AND isSubtask:true');
subtasks.forEach(subtask =>
  console.log("%s -> %s", subtask.getParent().getName(), subtask.getName()));

Gets a permalink for this task.

Return value

String

Example

// Outputs all tasks updated today and their permalinks.
rtm.getTasks('updated:today').forEach(task =>
  console.log("%s - %s", task.getName(), task.getPermalink()));

getPostponed()

Gets the number of times the task has been postponed.

Return value

number

Example

// Outputs the task(s) postponed the most.
const tasks = rtm.getTasks('postponed:>0 AND status:incomplete');

let postponed = 0;

tasks.forEach(task => {
  if (postponed < task.getPostponed()) {
    postponed = task.getPostponed();
  }
});

if (postponed === 0) {
  console.log("You have no postponed tasks.");
} else {

  console.log("The task(s) postponed the most (%d times):", postponed)

  tasks
    .filter(task => task.getPostponed() === postponed)
    .forEach((task, i) => console.log("%d. %s", i + 1, task.getName()));
}

getPriority()

Gets the priority of the task.

Return value

The Priority of the task.

Example

// Outputs the priority of all tasks added today.
const tasks = rtm.getTasks('added:today');
tasks.sort((a, b) => a.getName().localeCompare(b.getName()));
tasks.forEach(task =>
  console.log("%s - %s", task.getName(), task.getPriority()));

getStartDate()

Gets the date and time at which this task starts, or null if the task has no start date.

If hasStartTime is true then the start date indicates the instant in time at which the task starts.

If hasStartTime is false then the start date indicates midnight at the beginning of the day when the task starts.

Return value

The Date when the task starts, or null if the task has no start date.

Example

// Outputs the start date of all the tasks in "No Priority" list.
const tasks = rtm.getTasks('list:"No Priority"');
tasks.sort((a, b) => a.getStartDate() - b.getStartDate());
tasks.forEach(task =>
  console.log('%s - %s', task.getName(), task.getStartDate()));

getSubtasks()

Gets the subtasks of the task.

Return value

The list of subTasks.

Example

// Outputs tasks added today that have subtasks.
const tasks = rtm.getTasks('added:today AND hasSubtasks:true');
tasks.forEach(task => {
  console.log(task.getName());

  task.getSubtasks().forEach(subtask =>
    console.log('- %s', subtask.getName()));
});

getTags()

Gets the tags of the task.

Return value

The list of Tags.

Example

// Outputs tagged tasks added today.
const tasks = rtm.getTasks('added:today AND isTagged:true');
tasks.forEach(task => {
  const tags = task.getTags().map(tag => tag.getName());

  console.log('%s - %s', task.getName(), tags.join(', '));
})

getTaskSeries()

Gets the TaskSeries that this task belongs to.

Return value

The TaskSeries this task belongs to.

Example

// Outputs the number of tasks in the series for every task completed today.
const tasks = rtm.getTasks('completed:today');

if (tasks.length === 0) {
    console.log("There are no tasks completed today.")
} else {
    tasks.forEach(task => {
        const taskSeries = task.getTaskSeries();

        console.log(`${task.getName()} - ${taskSeries.getTasks().length}`);
    })
}

getUrl()

Gets the URL of the task.

Return value

The URL, or null if the task has no URL set.

Example

// Outputs tasks in "Urgent" list that have a URL set.
const tasks = rtm.getTasks("list:Urgent AND hasURL:true");
tasks.forEach(task =>
  console.log("%s - %s", task.getName(), task.getUrl()));

giveTo(userOrInvite)

Gives the task to the user.

Parameters

userOrInvite

The user or invite to give the task to.

Return value

The given Task.


giveToNobody()

Gives the task to nobody.

Return value

The updated Task.

Example

// Gives the tasks in "Not Urgent" list to nobody.
const tasks = rtm.getTasks('list:"Not Urgent" AND isGiven:true');
tasks.forEach(task => task.giveToNobody());
console.log('Gave %d task(s) to nobody.', tasks.length);

hasDueTime()

Determines whether the due date is marked as one with a time.

Return value

If true then the due date indicates the instant in time at which the task is due.

If false then the due date indicates midnight at the beginning of the day when the task is due.

Example

// Outputs the tasks due today and that have a due time set.
const tasks = rtm.getTasks('due:today AND status:incomplete');
tasks.forEach(task => {
  if (task.hasDueTime()) {
    console.log('%s - %s', task.getName(), task.getDueDate());
  }
});

hasStartTime()

Determines whether the start date is marked as one with a time.

Return value

If true then the start date indicates the instant in time at which the task starts.

If false then the start date indicates midnight at the beginning of the day when the task starts.

Example

// Outputs the tasks that start today and doesn't have a start time set.
const tasks = rtm.getTasks('start:today AND status:incomplete');
tasks.forEach(task => {
  if (!task.hasDueTime()) {
    console.log('%s - %s', task.getName(), task.getStartDate());
  }
});

increasePriority()

Increases the task priority. Does nothing if the task has the highest priority.

Return value

The updated Task.

Example

// Increases priority of all tasks located at "Banana Stand".
const tasks = rtm.getTasks('location:"Banana Stand"');
tasks.forEach(task => task.increasePriority());
console.log('Increased priority of %d task(s).', tasks.length);

isCompleted()

Determines whether the task is completed.

Return value

true if the task is completed, false otherwise.


isRecurring()

Determines whether this is a recurring task.

Return value

true if the task is recurring, false otherwise.


postpone()

Postpones the task. If the task has no due date or is overdue, its due date is set to today. Otherwise, the task due date is advanced a day.

Return value

The postponed Task.

Example

// Postpones the tasks due today and tagged with "bananas".
const tasks = rtm.getTasks('tag:bananas AND due:today');
tasks.forEach(task => task.postpone());

console.log('Postoned %d task(s).', tasks.length);

removeTags(...tags)

Removes the given tags from the task.

Parameters

...tags

A variable number of tags to remove. Tags cannot be empty or contain only whitespace. Every tag is lowercased and stripped of unsupported characters.

Return value

The updated Task.

Example

// Removes "urgent" and "someday" tags from all the tasks added today
const tasks = rtm.getTasks('added:today AND (tag:urgent OR tag:someday)');
tasks.forEach(task => task.removeTags('urgent', 'someday'));

console.log('Removed "urgent" and "someday" tags from %d task(s).',
  tasks.length);

setDueDate(date)

Sets the due date of the task.

Parameters

date

The new due date; setting to null clears the due date.

The time part of the date is replaced with midnight at the beginning of the day when the task is due.

Return value

The updated Task.

Example

// Searches tasks in "This Month's Bills" list and makes them due tomorrow.
const tasks = rtm.getTasks('list:"This Month\'s Bills"');
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
tasks.forEach(task => task.setDueDate(tomorrow));

console.log('Made %d task(s) due tomorrow.', tasks.length);

setDueTime(date)

Sets the due date and time of the task.

Parameters

date

The new due date and time; setting to null clears the due date and time.

The date indicates the instant in time at which the task is due.

Return value

The updated Task.

Example

// Searches tasks located at "Banana Stand" and makes them due in 10 minutes.
const tasks = rtm.getTasks('location:"Banana Stand"');
const in10Minutes = new Date();
in10Minutes.setMinutes(in10Minutes.getMinutes() + 10);
tasks.forEach(task => task.setDueTime(in10Minutes));

console.log('Made %d task(s) due at %s.', tasks.length, in10Minutes);

setEstimate(estimate)

Sets the task estimate.

Parameters

estimate

The new estimate; setting to null clears the estimate.

Return value

The updated Task.

Example

// Searches tasks without an estimate in "Big Project" list and
// sets the estimate to 1 hour 30 minutes.
const tasks = rtm.getTasks('list:"Big Project" AND hasTimeEstimate:false');
const estimate = rtm.newEstimate(1, 30);

tasks.forEach(task => task.setEstimate(estimate));

console.log('Set estimate for %d task(s).', tasks.length);

setList(list)

Moves the task to the given list.

Parameters

list

The list to move the task to.

Return value

The moved Task.

Example

// Moves all tasks from "Bananas" list to "Inbox".
const tasks = rtm.getTasks('list:Bananas');
const inbox = rtm.getInbox();
tasks.forEach(task => task.setList(inbox));

console.log('Moved %d task(s) to "Inbox".', tasks.length);

setLocation(location)

Sets the task location.

Parameters

location

The new location; setting to null clears the location.

Return value

The updated Task.

Example

// Moves "Take over the world" tasks from "Office" to "Home" location.
const tasks = rtm.getTasks('name:"Take over the world" AND location:Office');
const home = rtm.getLocations()
  .find(location => location.getName() === 'Home');

if (home != null) {
    tasks.forEach(task => task.setLocation(home));

    console.log('Moved %d task(s) from "Office" to "Home"', tasks.length);
} else {
    console.log('"Home" location not found.');
}

setName(name)

Sets the task name.

Parameters

name

The new name of the task. Cannot be empty or contain only whitespace.

Return value

The renamed Task.

Example

// Renames all "Buy bananas" tasks in the Inbox to "BUY BANANAS!!!".
const tasks =
  rtm.getTasks('name:"Buy bananas" AND list:Inbox AND status:incomplete');

tasks.forEach(task =>
  task.setName(task.getName().replace("Buy bananas", "BUY BANANAS!!!")));

console.log('Updated %d task(s).', tasks.length);

setParent(task)

Makes the task a subtask of the given parent.

Parameters

task

The new parent of the task; setting to null clears the parent.

Return value

The updated Task.

Example

// Adds an "Utmost importance" task, then makes it the parent of all the tasks
// in the Inbox that contain bananas.
const utmostImportance = rtm.addTask('Utmost importance');

const bananas = rtm.getTasks(
  'name:bananas AND list:Inbox AND status:incomplete AND isSubtask:false');

bananas.forEach(banana => banana.setParent(utmostImportance));

console.log('Updated %d task(s).', bananas.length);

setPriority(priority)

Sets the task priority.

Parameters

priority

The new priority of the task.

Return value

The updated Task.

Example

// Sets priority to `High` for "Pick up the milk" tasks in the Inbox.
const tasks = rtm.getTasks('name:"Pick up the milk" AND list:Inbox');
tasks.forEach(task => task.setPriority(rtm.Priority.High));
console.log('Updated %d task(s).', tasks.length);

setRecurrence(recurrence)

Sets the recurrence rule for the task.

Parameters

recurrence

The new recurrence rule to use; setting to null clears the recurrence rule.

Return value

The updated Task.

Example

// Makes "Take over the world" tasks repeat every month on the first Monday.
const tasks = rtm.getTasks('name:"Take over the world" AND status:incomplete');

tasks.forEach(task =>task.setRecurrence(
  rtm.newMonthlyRecurrence()
    .onlyOnWeekday(rtm.Weekday.Monday, rtm.WeekOfMonth.First)));

console.log('Updated %d tasks.', tasks.length);

setStartDate(date)

Sets the start date of the task.

Parameters

date

The new start date; setting to null clears the start date.

The time part of the date is replaced with midnight at the beginning of the day when the task starts.

Return value

The updated Task.

Example

// Searches tasks in "This Month's Bills" list and makes them start tomorrow.
const tasks = rtm.getTasks('list:"This Month\'s Bills"');
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
tasks.forEach(task => task.setStartDate(tomorrow));

console.log('Made %d task(s) start tomorrow.', tasks.length);

setStartTime(date)

Sets the start date and time of the task.

Parameters

date

The new start date and time; setting to null clears the start date and time.

The date indicates the instant in time at which the task starts.

Return value

The updated Task.

Example

// Searches tasks located at "Banana Stand" and makes them start in 10 minutes.
const tasks = rtm.getTasks('location:"Banana Stand"');
const in10Minutes = new Date();
in10Minutes.setMinutes(in10Minutes.getMinutes() + 10);
tasks.forEach(task => task.setStartTime(in10Minutes));

console.log('Made %d task(s) start at %s.', tasks.length, in10Minutes);

setTags(...tags)

Sets tags for the task. Clears the tags if no parameters provided.

Parameters

...tags

A variable number of tags to set. Tags cannot be empty or contain only whitespace. Every tag is lowercased and stripped of unsupported characters.

Return value

The updated Task.

Examples

// Sets tags for all "Call" tasks in "Monkey Business" list.
const tasks = rtm.getTasks('name:call and list:"Monkey Business"');
tasks.forEach(task => task.setTags('phone', 'calls'));
console.log('Updated %d tasks.', tasks.length);
// Clears tags for all "RSVP" tasks in "Monkey Business" list.
const tasks = rtm.getTasks(
  'name:rsvp and list:"Monkey Business" and isTagged:true');
tasks.forEach(task => task.setTags());
console.log('Updated %d tasks.', tasks.length);

setUrl(url)

Sets the task URL.

Parameters

url

The new URL; setting to null clears the URL.

Return value

The updated Task.

Example

// Adds a new task named "Write my first MilkScript", then sets its URL.
const task = rtm.addTask('Write my first MilkScript');
task.setUrl('https://www.rememberthemilk.com/services/milkscript/');
console.log('Added "%s" task.', task.getName());

uncomplete()

Marks the task and all its subtasks incomplete.

Return value

The uncompleted Task.

Example

// Searches "Take over the world" tasks completed today and uncompletes them.
const tasks = rtm.getTasks('name:"Take over the world" AND completed:today');
tasks.forEach(task => task.uncomplete());
console.log('Uncompleted %d task(s).', tasks.length);