Skip to content

Instantly share code, notes, and snippets.

@doug4j
Last active December 28, 2018 19:51
Show Gist options
  • Save doug4j/121819e4cdbf117d08f4cfecf002ad67 to your computer and use it in GitHub Desktop.
Save doug4j/121819e4cdbf117d08f4cfecf002ad67 to your computer and use it in GitHub Desktop.
Shows information from a selected project(s)
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 projectCount = 0
for (var i=0;i < selectedLen; i++) {
try{
var proj = selectedTree[i]
app.displayDialog("Project Selected\nindex: [" + i
+ "]\nid: [" + proj.id() + "]\nname: [" + proj.name()
+ "]\nstatus: " + proj.value().status() + "\nnumberOfAvailableTasks: [" + proj.value().numberOfAvailableTasks() + "]");
projectCount++
}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 project: " + e);
}
}
}
app.displayDialog(projectCount + " Selected Projects")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment