Hacking manual sorting support into custom perspectives


#1

First of all, this is a big hack and doesn’t work in almost all of the cases. You need to have your OmniFocus set up in a special way to utilize this, but here it is:

How does it work?

This script abuses 2 things:

  • The ‘estimated minutes’ field
  • The ‘sorting my duration’ setting

When executing, the script identifies the selected task inside the current tree, calculates a ‘estimated minutes’ setting and applies it in batch to all other tasks.

For example you have tasks t1, t2, t3 and t4. When running the script without any setting, the script freezes the current tasks position as it’s estimation. So t1 has a estimation of 0 minutes, t2 of 1 minute and so on.
Because the perspective is sorted by by duration, the task with estimation 0 will always be at the top.

Now when you execute the script to move a task, it sees it’s estimation setting and swaps it with the previous / next task. The perspective sees the change and re-sorts the tasks based on estimation again.

When can I use this?

When

  • You don’t use the estimation field for anything
  • You have your perspective set to ungrouped

There are a ton of cases when it won’t work. Any sort of grouping currently breaks the script. It also currently only works with 1 selection at a time. When selecting multiple tasks, it will pick the first one.

Also I am currently forcing focus on one perspective called “Next” since this is my workflow. Please update the script to use your perspective or the currently selected one.

var pName = "Today";
var w = ofDoc.documentWindows()[0];
// swap perspective
w.perspectiveName = pName;

How do I use this?

However you want. I am executing it through KeyboardMaestro (Execute JavaScript for Automation).

The script contains 3 functions: up(), down() and freeze().

up() and down() move the selected task up and down appropriately. freeze() is then writing the new order to OmniFocus. So you have to execute freeze() after each up() and down().

It’s enough to copy the entire thing into the script box and edit the last line to be

down();
freeze();

or

up();
freeze();

Download

here.

Please, if you improve the script consider opening a pull request so we can all benefit from the updates :)


#2

That’s a neat idea!

For me, I’ve used sort by Due or Defer date to hack this, given that you can specify date and time (so I could say 6:00pm, 6:01pm, 6:02pm, etc.) - that might be another consideration if you don’t want to use/repurpose the Estimated Time field.

Not that I know how to write AS. I’m just an idea guy. Haha.

Very cool approach here, though!

ScottyJ


#3

I think Defer and Due are too important to abuse them for a arbitary order. They are probably the fields I change the most with a bunch of applescript. I constantly push tasks between perspectives and barely hand-edit them.

Estimation however - as a guy doing a lot in Scrum and other agile methods, “estimation” in form of minutes/hours/days always seemed… off to me. It is very difficult for me to get even close to the correct amount of time needed because most of my tasks can be very unpredictable. Sometimes a “1h” task explodes to 2 days because of unexpected behavior, sometimes the other way around. Constant Re-scheduling is tiresome so I don’t bother. (I’d love a freeform estimation field though! Let me put in whatever I want. Be it size in form of S/M/L/XL or something like story points).

I never used applescript before around 1-2 weeks ago. It’s actually quite simple :)


#4

Totally fair. Just spitballing, that’s how I manually order tasks once I’ve set up my day.

Oh! I’d be keen to learn. My programming knowledge is mostly limited to HTML and CSS, although I used to write IRCscript like a thousand years ago haha. Do you have suggestions on best places to start?

Thanks!

ScottyJ


#5

To be honest, I just started with reading OmniFocus scripts and trying to understand how they work. A massive help is the script editor. You can open the entire OmniFocus documentation with it and then everything makes a lot more sense. (File Menu)

I personally found the JXS version a lot easier to understand than the verbose applescript but it was very difficult to find pure JXS examples that don’t use the OmniFocus library from pixelsnatch.

I have a little script collection up on github that you can use for getting the hang of it. They are mostly very simple things like updating a few fields or setting focus on something. This one here for example is updating all selected tasks due dates to today 11pm. Or this one simple sets the current view to “first available”.


#6

Links added to my shiny new Someday/Maybe “Learn Applescript” project - thank you again!


#7

@dvcrn

Thanks for sharing your script here. Would like to adapt it just a little bit.

I was able to launch the script in debug mode, adding a
debugger;
statement in the code and then stepping into it.

However, I could not look into the various objects in the global variables column for what properties and methods were available in the object.

Is this possible to see what the objects hold when debugging JXA scripts?

Thank you.