Created
December 31, 2018 19:08
-
-
Save doug4j/2f02e20866db96d041e04b97ddcc414b 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
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 | |
if (selectedLen == 0) { | |
//app.displayDialog("Nothing selected in Omnifocus"); | |
} else { | |
//app.displayDialog("Content Selected count: " + selectedTree.length) | |
} | |
var totalItems = 0; | |
var totalMinutes = 0 | |
for (var i=0;i < selectedLen; i++) { | |
try{ | |
var task = selectedTree[i] | |
var hasParentTask = false; | |
var parentTask = task.value().parentTask(); | |
if (parentTask !== null) { | |
hasParentTask = true | |
} | |
app.displayDialog("Task Selected\n" | |
+ "index: [" + i + "]\n" | |
+ "id: [" + task.id() + "]\n" | |
+ "name: [" + task.name() + "]\n" | |
+ "hasParentTask: [" + hasParentTask + "]\n" | |
+ "descendant count: [" + task.descendantTrees().length + "]\n" | |
+ "completed: [" + task.value().completed() + "]\n" | |
+ "estimatedMinutes: [" + task.value().estimatedMinutes() + "]\n" | |
+ "tags: [" + tagsNamesAsString(task.value().tags()) + "]"); | |
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 tagsNamesAsString(tags) { | |
if (tags === null) { | |
return ""; | |
} | |
var answer = "" | |
tags.forEach(tag => { | |
if (answer === "") { | |
answer = tag.name() | |
} else { | |
answer = answer + ", " + tag.name() | |
} | |
}); | |
return answer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment