Last active
September 5, 2016 07:11
-
-
Save cescoffier/36e8331b57b5ff89ecd38ae17e3934ac to your computer and use it in GitHub Desktop.
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
ObjC.import('Cocoa'); | |
ObjC.import('Foundation') | |
var args = $.NSProcessInfo.processInfo.arguments | |
var argv = [] | |
var argc = args.count // -[NSArray count] | |
for (var i = 0; i < argc; i++) { | |
argv.push( ObjC.unwrap( args.objectAtIndex(i) ) ) // -[NSArray objectAtIndex:] | |
} | |
delete args | |
var done = []; | |
var app = Application("OmniFocus"); | |
var doc = app.defaultDocument; | |
var tasks = doc.flattenedTasks.whose({id: argv[2]}); | |
var completedTasks = []; | |
for (var i = 0; i < tasks.length; i++) { | |
tasks[i].completed = true; | |
completedTasks.push(tasks[i].name()); | |
} | |
completedTasks; | |
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
ObjC.import('Cocoa'); | |
ObjC.import('Foundation') | |
var args = $.NSProcessInfo.processInfo.arguments | |
var argv = [] | |
var argc = args.count // -[NSArray count] | |
for (var i = 0; i < argc; i++) { | |
argv.push( ObjC.unwrap( args.objectAtIndex(i) ) ) // -[NSArray objectAtIndex:] | |
} | |
delete args | |
var done = []; | |
var app = Application("OmniFocus"); | |
var doc = app.defaultDocument; | |
var tasks = doc.flattenedTasks.whose({id: argv[2]}); | |
var contexts = doc.flattenedContexts; | |
var waiting; | |
for (var i = 0; i < contexts.length; i++) { | |
if (contexts[i].name() == "Waiting") { | |
waiting = contexts[i]; | |
} | |
} | |
if (! waiting) { | |
throw "Unable to find the 'Waiting' context" | |
} | |
var movedTasks = []; | |
for (var i = 0; i < tasks.length; i++) { | |
tasks[i].context = waiting; | |
tasks[i].note = argv[3]; | |
movedTasks.push(tasks[i].name()); | |
} | |
movedTasks; | |
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
var report = []; | |
var app = Application("OmniFocus"); | |
var doc = app.defaultDocument; | |
var tasks = doc.flattenedTasks.whose({completed: false}); | |
for (var i = 0; i < tasks.length; i++) { | |
report.push(toJson(tasks[i])); | |
} | |
JSON.stringify(report); | |
function toJson(task) { | |
var note = task.note(); | |
var res = {}; | |
res.name = task.name(); | |
res.id = task.id(); | |
res.completed = task.completed(); | |
res.flagged = task.flagged(); | |
if (note) { | |
res.note = note.text; | |
} else { | |
res.note = ""; | |
} | |
res.project = task.container().name(); | |
if (res.project == "OmniFocus") { | |
res.project = "Inbox"; | |
} | |
res.inInbox = task.inInbox() | |
if (task.context()) { | |
res.context = task.context().name(); | |
} | |
res.creationDate = task.creationDate(); | |
res.modificationDate = task.modificationDate(); | |
if (task.deferDate()) { | |
res.deferDate = task.deferDate(); | |
} | |
if (task.dueDate()) { | |
res.dueDate = task.dueDate(); | |
} | |
if (task.completionDate()) { | |
res.completionDate = task.completionDate(); | |
} | |
return res; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
3 examples of JavaScript automation tasks dealing with Omnifocus.
retrieve-tasks-from-omnifocus
Retrieve all tasks from Omnifocus and export them as JSON. The JSON output is written the "out" stream of the process, so it can be easily read by a Java program or whatever.
Be aware that the export take around 1 second per task.... Update the query to make it faster.
put-task-on-hold
This script is launched from the command line (
osascript put-tasks-on-hold.scpt $task_id
).It searches for the
Waiting
context (to update if your on-hold context is named differently). Then it looks for the task with the given id (argument) and set the context to the found one.complete-task
This script is launched from the command line (
osascript put-tasks-on-hold.scpt $task_id
).Search for the task with the given id and mark it as completed.