omnifocus-widget icon indicating copy to clipboard operation
omnifocus-widget copied to clipboard

Feature request: Update for Omni automation

Open tooh opened this issue 5 years ago • 1 comments

https://discourse.omnigroup.com/t/are-there-any-javascript-experts-in-the-house/23296

tooh avatar Oct 21 '20 08:10 tooh

FIY: I have updated the code in the discourse post to work with tags vs context. My first run it shows way too much tasks, but since I don't use this any more, I'll just throw the code out here, for anyone who might be interested.

of-flaggedTasks.scpt

Please note that context has been replaced by tag in the final output. That means the index.coffee file needs to be adjusted too, or check the arrow below to revert back to context.

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 primaryTag = (task.primaryTag() !== null) ? task.primaryTag().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(),
				tag: primaryTag,  // <-- change the first 'tag' into 'context' to match the index.coffee file.
				project: project,
				note: task.note(),
				due: taskDue,
				
			});
		}
	});		
	
	var retObj = {
		'tasks' : taskList,
		'count' : taskList.length
	};

	return JSON.stringify(retObj);
}

hepabolu avatar Mar 12 '23 11:03 hepabolu