Access moment.js in a TaskPaper script


#1

You mention Moment.js is used for parsing dates in TaskPaper. Is there a global variable, or some way we can access Moment from inside a TaskPaper script?

Alternatively, Apple’s documented way to import/require scripts is not working for me. Does this work for anyone else?


#2

I’m not sure about Apple’s import method, but moment is actually available in TaskPaper’s default script context.

Here’s an example:

function TaskPaperContextScript(editor) {
  var outline = editor.outline
  var item = outline.createItem(moment().format('MMMM Do YYYY, h:mm:ss a'))
  outline.root.appendChildren(item)
}

Application("TaskPaper").documents[0].evaluate({
  script: TaskPaperContextScript.toString()
})

This is undocumented and could change in future, but I don’t expect it to.


#3

Ah perfect, thanks.