-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
54 lines (43 loc) · 1.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const osa = require('osa2');
const getInboxCount = osa(() => Application('OmniFocus').defaultDocument.inboxTasks().filter((task) => task.completed() === false).length);
const getTasks = osa((includeCompleted = false) => {
const OmniFocus = Application('OmniFocus')
const firstWindow = OmniFocus.windows[0]
for(var i = 0; i < OmniFocus.windows.length; i++) {
console.log(OmniFocus.windows[i].name())
}
const tasks = firstWindow.document().flattenedTasks().filter(task => task.completed() === false || task.completed() == includeCompleted)
var retVal = [];
for(var i = 0; i < tasks.length; i++) {
retVal.push({
name: tasks[i].name(),
id: tasks[i].id(),
note: tasks[i].note(),
inInbox: tasks[i].inInbox(),
flagged: tasks[i].flagged(),
completed: tasks[i].completed(),
deferDate: tasks[i].deferDate()
})
}
return retVal;
});
const markTaskComplete = osa((taskId) => {
const task = Application('OmniFocus').defaultDocument.flattenedTasks().filter(task => task.id() === taskId)
if (task) {
return Application('OmniFocus').markComplete(task)
}
return false
});
const markTaskIncomplete = osa((taskId) => {
const task = Application('OmniFocus').defaultDocument.flattenedTasks().filter(task => task.id() === taskId)
if (task) {
return Application('OmniFocus').markIncomplete(task)
}
return false
});
module.exports = {
getInboxCount,
getTasks,
markTaskComplete,
markTaskIncomplete
}