Last active
October 11, 2024 00:03
-
-
Save doug4j/45c1745b4fc65f3e41c1da92dcfe087c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jshint esversion:6 | |
(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; | |
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; | |
} | |
} | |
} | |
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); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment