Skip to content

Instantly share code, notes, and snippets.

@doug4j
Last active October 11, 2024 00:03
Show Gist options
  • Select an option

  • Save doug4j/45c1745b4fc65f3e41c1da92dcfe087c to your computer and use it in GitHub Desktop.

Select an option

Save doug4j/45c1745b4fc65f3e41c1da92dcfe087c to your computer and use it in GitHub Desktop.

Revisions

  1. doug4j revised this gist Feb 1, 2019. 1 changed file with 51 additions and 29 deletions.
    80 changes: 51 additions & 29 deletions of3-effort-by-selected-report.js.scpt
    Original file line number Diff line number Diff line change
    @@ -1,35 +1,57 @@
    var app = Application('OmniFocus');
    app.includeStandardAdditions = true;
    var doc = app.defaultDocument;
    var content = doc.documentWindows.at(0).content;
    var selectedTree = content.selectedTrees();
    var selectedLen = selectedTree.length
    // jshint esversion:6

    var totalItems = 0;
    var totalMinutes = 0
    (function() {
    var app = Application('OmniFocus'); //This assumes that OmniFocus is installed on MacOS
    app.includeStandardAdditions = true;
    var doc = app.defaultDocument;
    var content = doc.documentWindows.at(0).content;
    var selectedTree = content.selectedTrees();
    var selectedLen = selectedTree.length;

    for (var i=0;i < selectedLen; i++) {
    try{
    var task = selectedTree[i]
    var hasParentTask = false;
    var estimatedMinutes = task.value().estimatedMinutes()
    if (estimatedMinutes !== null) {
    totalMinutes = totalMinutes + estimatedMinutes;
    var totalItems = 0;
    var totalMinutes = 0;

    for (var i=0;i < selectedLen; i++) {
    try{
    var task = selectedTree[i];
    //var hasParentTask = false;
    if (isLeafTask(task)) {
    var estimatedMinutes = task.value().estimatedMinutes();
    if (estimatedMinutes !== null) {
    totalMinutes = totalMinutes + estimatedMinutes;
    }
    totalItems = totalItems + 1;
    }
    }catch(e) {
    if (e.message === "User canceled.") {
    return; //get out of the loop (end the program)
    } else {
    app.displayDialog("[Exception] Content Selected index [" + i + "] is not a task: " + e);
    return;
    }
    }
    totalItems = totalItems + 1
    }catch(e) {
    if (e.message === "User canceled.") {
    break; //get out of the loop (end the program)
    } else {
    // app.displayDialog("[Exception] Content Selected index [" + i + "] is not a task: " + e);
    }

    function isLeafTask(item) {
    try {
    if(item.value().inInbox()) {
    return true;
    }
    if (item.value().containingProject().id() === item.value().id()) {
    //This is a project, tag, or some other top-level container
    return false;
    }
    return item.value().numberOfTasks() == 0;
    } catch (e) {
    return false;
    }
    }
    }

    var msg = ""
    if (totalItems > 1) {
    msg = "" + Math.floor(totalMinutes / 60) + "h " + (totalMinutes % 60).toFixed(0) + "m " + totalItems + " items"
    } else {
    msg = "" + Math.floor(totalMinutes / 60) + "h " + (totalMinutes % 60).toFixed(0) + "m " + totalItems + " item"
    }
    app.displayDialog(msg)
    var msg = "";
    if (totalItems > 1) {
    msg = "" + Math.floor(totalMinutes / 60) + "h " + (totalMinutes % 60).toFixed(0) + "m " + totalItems + " items";
    } else {
    msg = "" + Math.floor(totalMinutes / 60) + "h " + (totalMinutes % 60).toFixed(0) + "m " + totalItems + " item";
    }
    app.displayDialog(msg);
    })();
  2. doug4j revised this gist Dec 31, 2018. 1 changed file with 35 additions and 1 deletion.
    36 changes: 35 additions & 1 deletion of3-effort-by-selected-report.js.scpt
    Original file line number Diff line number Diff line change
    @@ -1 +1,35 @@
    a
    var app = Application('OmniFocus');
    app.includeStandardAdditions = true;
    var doc = app.defaultDocument;
    var content = doc.documentWindows.at(0).content;
    var selectedTree = content.selectedTrees();
    var selectedLen = selectedTree.length

    var totalItems = 0;
    var totalMinutes = 0

    for (var i=0;i < selectedLen; i++) {
    try{
    var task = selectedTree[i]
    var hasParentTask = false;
    var estimatedMinutes = task.value().estimatedMinutes()
    if (estimatedMinutes !== null) {
    totalMinutes = totalMinutes + estimatedMinutes;
    }
    totalItems = totalItems + 1
    }catch(e) {
    if (e.message === "User canceled.") {
    break; //get out of the loop (end the program)
    } else {
    // app.displayDialog("[Exception] Content Selected index [" + i + "] is not a task: " + e);
    }
    }
    }

    var msg = ""
    if (totalItems > 1) {
    msg = "" + Math.floor(totalMinutes / 60) + "h " + (totalMinutes % 60).toFixed(0) + "m " + totalItems + " items"
    } else {
    msg = "" + Math.floor(totalMinutes / 60) + "h " + (totalMinutes % 60).toFixed(0) + "m " + totalItems + " item"
    }
    app.displayDialog(msg)
  3. doug4j created this gist Dec 31, 2018.
    1 change: 1 addition & 0 deletions of3-effort-by-selected-report.js.scpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    a