Last active
October 10, 2019 12:53
-
-
Save shedali/eb65c389eea0282f2cf5cd12a2cd0060 to your computer and use it in GitHub Desktop.
test grab due tasks with jxa in node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const runJxa = require("run-jxa"); | |
const _ = require('lodash'); | |
(async () => { | |
const result = await runJxa(() => { | |
var of = Application("OmniFocus"); | |
var doc = of.defaultDocument; | |
return getTasks(); | |
function getTasks() { | |
var today = new Date(); | |
var dueDate = new Date(today.setDate(today.getDate() + 7)); | |
var taskList = []; | |
var flattenedTasks = doc.flattenedTasks.whose({ | |
_or: [ | |
{ | |
completed: false, | |
flagged: true, | |
blocked: false, | |
_match: [ObjectSpecifier().parentTask.flagged, false] | |
}, | |
{ | |
completed: false, | |
blocked: false, | |
_match: [ObjectSpecifier().parentTask.dueDate, { "<": dueDate }] | |
} | |
] | |
}); | |
flattenedTasks().forEach(function(task) { | |
if ( | |
(!task.context.hidden && !task.deferDate()) || | |
today > task.deferDate() | |
) { | |
var context = task.context() !== null ? task.context().name() : ""; | |
var project = | |
task.container() !== null ? task.container().name() : ""; | |
var taskDue = false; | |
if (task.dueDate() || task.parentTask.dueDate()) { | |
taskDue = true; | |
} | |
taskList.push({ | |
name: task.name(), | |
id: task.id(), | |
context: context, | |
project: project, | |
note: task.note(), | |
due: taskDue | |
}); | |
} | |
}); | |
var retObj = { | |
tasks:taskList, | |
count: taskList.length | |
}; | |
return taskList.map((task)=>'- '+ task.project +": " + task.name); | |
} | |
}); | |
return result; | |
})().then((R)=>{ | |
R&&console.log(R) | |
}).catch(e=>{ | |
console.error(e); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment