You'll need to compile this as OmniFocus.scpt
and save it at ~/Library/Script Libraries
so that you can import it in another script.
// An example of how to use OmniFocusLibrary.js
of = Library('OmniFocus')
codingTasks = of.tasksWithContext('coding')
today = new Date
today.setHours(17)
of.setDefer(codingTasks, today)
// Using the parse method
of.parse('Do something! @home ::misc #4pm #tomorrow //This is a note')
I intended to include natural language date parsing in this script, and I've been trying to get the chrono library to work in my OmniFocus library, but to no avail. Anyone willing to help with this would have my deepest thanks. As it stands, you need to pass a date object into any function that deals with setting deferDate or dueDate.
alert(text)
— display AppleScript alert dialogallTasks()
— all tasks in your default documentallProjects()
— all projects in your default documentcopy(text)
— copies text to OS X's clipboardtasksWithName(name, inputTasks)
— all tasks that fuzzy matchname
—inputTasks
defaults toallTasks
tasksWithContext(name, inputTasks)
— all tasks that have a context that fuzzy matchname
—inputTasks
defaults toallTasks
projectsWithName(name, inputProjects)
— all projects that fuzzy matchname
—inputProjects
defaults toallProjects
allWithName(name)
— all tasks that fuzzy matchname
with a task title, context or containing projectsetDefer(tasks, deferDate)
— defer an array of tasks withdeferDate
setDue(tasks, dueDate)
— set an array of tasks' due date withdueDate
setContext(tasks, contextName)
— set an array of tasks' context tocontextName
inboxTasks()
— all inbox tasksgetContext(contextName)
— gets the first context object that matchescontextName
getProject(projectName)
— gets the first project object that matchesprojectName
newTask(text, place, deferDate, dueDate)
— creates a new OmniFocus task objectparse(text)
— parse a string of transport text as a taskpushTask(task, project)
— pushtask
toproject
arrayprefixTasksWith(tasks,text)
— prefix each task intasks
withtext
updateInboxTasks(context, project, deferDate, dueDate)
— update all inbox tasks with the samecontext
,deferDate
, anddueDate
and add them toproject
For those who don't know about transport text, it's a format that OmniFocus uses to parse task information like so:
Do something! @home ::misc #5pm #tomrrow //This is a note
The !
makes Do something
a flagged task. @home
sets the context to "home". ::
is used for matching a project. Both @
and ::
will fuzzy match existing contexts and projects. The first #
is used for a defer date, while the second #
is for a due date. Both support natural language parsing like the inspector in OmniFocus. Word of caution though, if only one #
is present, OmniFocus assumes it's a due date. Lastly, //
starts the note for a task.