Are there any javascript experts in the house?

Hi

I have found an excellent tool for my Omnifocus workflow. Its call Übersicht and lets you display javascript widgets on your OSX desktop. Unfortunately i have only found one Omnifocus widget, and it only display flagged actions. Thats is not the way i use Omnifocus, as i rather want a today-view showing all actions that are not deferred.

This is the today perspective i would like to display on my desktop - so that i always have my todo list visually when im at my desk.
Its heavy influenced by Macsparky and his Omnifocus workflow.

Javascript is not my speciality, but i have the impression that a small tweak to the flagged widget will allow to show my perspective.

Link to Übersicht

Link to OmniFocus Flagged Task Widget

Link to widget library for the interested: tracesof. net/uebersicht-widgets/

Anyone want to give it a go? It would be greatly appreciated


This is how the javascript look:

of = Application(‘OmniFocus’);

doc = of.defaultDocument;

getFlaggedTasks();

function getFlaggedTasks(){
taskList = [];
tasks = doc.flattenedTasks.whose({completed: false, flagged: true})();
var today = new Date();
tasks.forEach(function(task){
if ( (!task.deferDate()) || (today > task.deferDate()) ) {
context = (task.context() !== null) ? task.context().name() : ‘’;
project = (task.container() !== null) ? task.container().name() : ‘’;
taskList.push({
name: task.name(),
id: task.id(),
context: context,
project: project,
note: task.note(),

		});
	}
});

retObj = {
	'tasks' : taskList,
	'count' : taskList.length
};

return JSON.stringify(retObj);

}

I use GeekTool and have an Applescript (straight Applescript not JavaScript) that allows me to post different Perspectives. I’ve thought one day to change to Übersicht, although for now the investment is too high. If you are interested in adapting what I have to what you have, let me know.

Otherwise, my quick suggestion is to change the flagged:true to flagged:false. That should give you a long list beyond the perspective you have. You may need to try remainingTasks rather than flattenedTasks. So, what happens with this change …

tasks = doc.remainingTasks.whose({completed:false,flagged:false})();


JJW

If i cant get the work with the javascript i might look into geektool - thank you.

Hi did you ever get this working?

No unfortunately not. I would still love to find a solution.

@jr52mar and @dynamitleo, I don’t know if this helps or not but I use Ubersicht heavily. I took the widget you mentioned and tweaked it to display tasks that are Due Soon or Flagged which effectively puts my Dashboard on my Desktop. Here’s the code for that:

of = Application('OmniFocus');
doc = of.defaultDocument;
getTasks();

function getTasks(){
	var today = new Date();
	dueDate = new Date(today.setDate(today.getDate()+7));
	taskList = [];
	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()) ) {
			context = (task.context() !== null) ? task.context().name() : '';
			project = (task.container() !== null) ? task.container().name() : '';
			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,
				
			});
		}
	});
		
	retObj = {
		'tasks' : taskList,
		'count' : taskList.length
	};

	return JSON.stringify(retObj);
}

Thanks, however this only shows any tasks which are “flagged” which is strange

I need it to only show tasks which belong to a certain context “TESTCONTEXT” and also to show any overdue tasks (as far back as a month)

The reason I need to show only a certain context is I use OF to track actions with my team

Hi, @joebuhlig

I’d really like to use the code you shared above but when I try, I get an error that states: ./omifocusflags.widget/of-availTasks.scpt:0:2: script error: A “of” can’t go here. (-2740)

(I’ve saved your code as of-availTasks.scpt and just updated the index.coffee file to point to it instead of the original script.)

If you’ve updated to High Sierrra, can you tell me if this widget is still working properly for you? I’ve noticed some odd behavior with another widget and a second one doesn’t work at all, so I’d like to rule that out before starting to tinker further.

I didn’t actually change anything in your code, so I’m curious if it’s still working for you.

Thanks so much!

I did upgrade to High Sierra. And it’s still running great on my machine. Looking closer at the code, I noticed that there are a number of variables that weren’t declared correctly for javascript. Here’s the updated version that’s still running fine for me but with the standards in place:

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);
}

I know from how frequently I see you on the web that you’re busy and I really appreciate you taking a few minutes to help me. This worked!

Thanks again, Joe!

1 Like