Skip to content

Instantly share code, notes, and snippets.

@shedali
Created April 12, 2018 23:09
Show Gist options
  • Save shedali/28f58146d896c9c5f46add518264b6fb to your computer and use it in GitHub Desktop.
Save shedali/28f58146d896c9c5f46add518264b6fb to your computer and use it in GitHub Desktop.
Get Flagged Omnifocus Tasks Applescript
# javascript for mac - get OF flagged tasks
var of = Application('OmniFocus');
var doc = of.defaultDocument;
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: false, blocked: false, dueDate: {"<":dueDate}},
{completed: false, flagged: true, blocked: false},
{completed: false, flagged: false, blocked: false , _match: [ObjectSpecifier().parentTask.flagged, true] },
{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 JSON.stringify(retObj);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment