MilkScript

Automate tasks with MilkScript.

menu

Tag

Represents a tag. Tags are like keywords or labels that you can add to a task to make it easier to find and organize later.


addTask(name, parse)

Adds a new task marked with this tag.

Parameters

name

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

parseOptional

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

Return value

The newly added Task.

Example

// Adds a new task "Call the electrician" tagged with "phone".
const phone = rtm.getTags().find(tag => tag.getName() === 'phone');

if (phone != null) {
  const task = phone.addTask('Call the electrician');

  console.log('Added "%s" task tagged with "%s".',
    task.getName(), phone.getName());
} else {
  console.log('"phone" tag not found.');
}

delete()

Removes the tag from all the tasks marked with it, then deletes the tag.

Return value

undefined

Example

// Deletes "errand" tag.
const errand = rtm.getTags().find(tag => tag.getName() === 'errand');

if (errand != null) {
  errand.delete();

  console.log('Deleted "%s" tag.', errand.getName());
} else {
  console.log('"errand" tag not found.');
}

getCreatedDate()

Gets the date the tag was created.

Return value

Date

Example

// Outputs all tags and their created dates.
rtm.getTags().forEach(tag =>
  console.log("%s - %s", tag.getName(), tag.getCreatedDate()));

getModifiedDate()

Gets the date the tag was last modified.

Return value

Date

Example

// Outputs all tags and their modified dates.
rtm.getTags().forEach(tag =>
  console.log("%s - %s", tag.getName(), tag.getModifiedDate()));

getName()

Gets the name of this tag.

Return value

The name of the Tag.

Example

// Outputs all tags.
rtm.getTags().forEach(tag => console.log(tag.getName()));

Gets a permalink for this tag.

Return value

String

Example

// Outputs the list of tags and their permalinks.
rtm.getTags().forEach(tag =>
  console.log("%s - %s", tag.getName(), tag.getPermalink()));

getTasks(filter)

Gets all tasks marked with this tag.

Parameters

filterOptional

If specified, only tasks matching the given criteria are returned.

Return value

The list of Tasks marked with this tag.

Example

// Outputs the number of incomplete tasks tagged with "bill".
const bill = rtm.getTags().find(tag => tag.getName() === 'bill');

if (bill != null) {
  console.log('Incomplete tasks tagged with "%s": %d',
    bill.getName(), bill.getTasks('status:incomplete').length);
} else {
  console.log('"bill" tag not found.');
}

isFavorite()

Determines whether the tag is marked as a favorite.

Return value

true if the tag is marked as a favorite, false otherwise.

Example

// Outputs all favorite tags.
rtm.getTags().forEach(tag => {
  if (tag.isFavorite()) {
    console.log(tag.getName());
  }
});

setFavorite(favorite)

Sets whether the tag is marked as a favorite.

Parameters

favorite

true to mark the tag as a favorite, false otherwise.

Return value

The updated Tag.

Example

// Favorites "computer" tag.
const computer = rtm.getTags().find(tag => tag.getName() === 'computer');

if (computer != null) {
  computer.setFavorite(true);

  console.log('Marked "%s" tag as a favorite.', computer.getName());
} else {
  console.log('"computer" tag not found.');
}

setName(name)

Sets the tag name.

Parameters

name

The new name of the tag. The name is lowercased and stripped of unsupported characters. It cannot be empty or contain only whitespace.

Return value

The renamed Tag.

Example

// Renames "mail" tag to "email".
const mail = rtm.getTags().find(tag => tag.getName() === 'mail');

if (mail != null) {
  mail.setName('email');

  console.log('Renamed "mail" tag');
} else {
  console.log('"mail" tag not found');
}