Total Time script in OF3 for macOS


#1

Is Byler’s Total Time script working for anyone in OF3 for Mac? I get an error and I don’t understand scripting well enough to try to fix it. If anyone has this working (or made it work) I’d love to hear about it—the script is pretty important to my workflow. Thank you.


Total Duration Time in OmniFocus
A script to calculate duration tasks in OF2
#2

Looks like changing ‘context’ to ‘tag’ on line 63 is probably all that needs to be done. Should look like this:

set validSelectedItemsList to value of (selected trees where class of its value is not item and class of its value is not folder and class of its value is not tag and class of its value is not perspective)

Edit: A little easier: Can download an updated version here.


#3

Excellent, thank you! That did the trick.


#4

Thank you @deaghean!


#5

Apologies, complete novice non-tech here. Copied and pasted fixed script over the original one in Omnifocus/Help/Open Scripts Folder, customized toolbar to add link to revised script, but when I click on link after selecting 3 tasks with estimated time entries, nothing happens. Any sense of what I might be doing wrong? Thanks!


#6

One possible theory: Is the alert style for Script Editor under System Preferences > Notifications set to None rather than Banners or Alerts?


#7

Hmm, Good idea but that’s not it either. I don’t have growl, so I left the default setting at the top of the script to useGrowl: false. No Mac notification for me.


#8

And presumably you’re not getting any sort of error or dialog when you run the script? It just does nothing?


#9

Correct, just does nothing. Screen shot attached.


#10

Another shot in the dark: confirm that the entire script made it into your file. For instance, omitting the main() at the end is a good way to have that script run without producing any output.


#11

Thanks again deaghean. No success, but I did get this error message.

The operation couldn’t be completed. osascript: OpenScripting.framework - scripting addition “/Library/ScriptingAdditions/Adobe Unit Types.osax” cannot be used with the current OS because it has no OSAXHandlers entry in its Info.plist.

/Users/kiesel/Library/Application Scripts/com.omnigroup.OmniFocus3/TimeTotal.scpt: execution error: This script contains uncompiled changes and cannot be run. (-2700)

My OSX is High Sierra 10.13.6. Does this mean I have to upgrade the OS to 10.14 for the script to work?


#12

I don’t think so. If that Adobe Unit Types error is the culprit, it probably worked with older OSes rather than newer ones. It’s an old article, but I wonder if running the steps in Solution 1 here would solve that particular issue.


#13

Great, you saved me! Thanks :-)


#14

I have the same problem of getting the Total Time script to produce a message. I changed the context to tag, checked the notification settings - all good. In the Script Editor it produces the right notification in the results tab, but in Omnifocus it does simply nothing. No error message at all. Any ideas?


#15

For some reason it started to work now: A script complete message appears with the correct total time. I haven’t changed anything.


#16

Working for me as well. I did not o a line-by-line comparison with the version linked above, but grabbed the latest from Dan’s Github page here. I had to comment out the subroutine labeled on notifyWithGrowl because of odd characters. This was perfectly fine as I use macOS’s notification system anyway.


#17

If it’s helpful, here is a script in javascript.

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)

Or see https://gist.github.com/doug4j/45c1745b4fc65f3e41c1da92dcfe087c


#18

I am a total beginner with scripts and although I once had this one working, it has disappeared. I’ve since redone it and it shows up in my Script Editor and works when I hit the play button in the Script Editor but the icon to total the task durations in OF is not showing up! Any clue what I can do to get this there? I tried going to “view” and “customize toolbar” but it’s not there either. I really don’t want to have to highlight my tasks then open the Script Editor to calculate this each time I need to. Thank you!!


#19

The java script worked great for me. Also this may get me started on a more modern language for this automation.