Hi,
I modified the alphabetical sort script to sort by dueDate. It works, except that it puts tasks without a due date at the top. I would like them to show up after the ones that do have a due date.
I’d love to get some help! Here is the script as it stands now. Thanks in advance.
– Henri
/*{
"type": "action",
"targets": ["omnifocus"],
"author": "Picciotto Automator",
"identifier": "com.omni-automation.of.date-sort-project-tasks",
"version": "1.0",
"description": "This action will sort the tasks of the selected non-sequential project in due date order.",
"label": "Date-Sort Project Tasks",
"shortLabel": "Date-Sort"
}*/
(() => {
var action = new PlugIn.Action(function(selection, sender){
// action code
// selection options: tasks, projects, folders, tags
var project = selection.projects[0]
if (project.containsSingletonActions){
var tasks = project.task.children
if (tasks.length > 1){
tasks.sort((a, b) => {
var x = a.dueDate;
var y = b.dueDate;
if (x < y) {return -1;}
if ((x > y) || (x = null)) {return 1;}
return 0;
})
moveTasks(tasks, project)
}
}
});
action.validate = function(selection, sender){
// validation code
// selection options: tasks, projects, folders, tags
return (selection.projects.length === 1)
};
return action;
})();