I am trying to create a simple script to tally the percentage complete on a selected project, where %complete = completed tasks/total tasks. I must admit that I am floundering on issues of windows, documents, contents, and projects (flattened or not). Here is my test starting point ...
The first parts work to parse the list for only one project. How do I extract the project from theSelection in order to parse its number of tasks and completed tasks? I also eventually want this script to run on a project that may be selected in either the left or right pane. What caveats apply?
Past the basics, this script could be used in repeat loops to do a statistical report. My immediate end use is to use the percentage completed on a selected project to adjust the value on a corresponding goal in Goalscape.
Thanks!
Code:
(* This script calculates a percentage completion on a selected project *) tell application "OmniFocus" set oC to the content of front window set theSelection to (value of every selected tree of oC) if ((count of theSelection) < 1) then display alert "You must first select a Project to run this." as warning return end if if ((count of theSelection) > 1) then display alert "You currently can only select one Project to run this." as warning return end if (* if the type of theSelection is not project then display alert "You can only run this on a Project." as warning return end if set theNumber to the (number of tasks in theSelection) set theNumberCompleted to the (number of completed tasks in theSelection) set thePercentage = theNumberCompleted*100/theNumber *) end tell
Past the basics, this script could be used in repeat loops to do a statistical report. My immediate end use is to use the percentage completed on a selected project to adjust the value on a corresponding goal in Goalscape.
Thanks!