Skip to content

Instantly share code, notes, and snippets.

@doug4j
Last active December 29, 2018 13:26
Show Gist options
  • Save doug4j/a6af365ebc2d212cfca039df5f67387d to your computer and use it in GitHub Desktop.
Save doug4j/a6af365ebc2d212cfca039df5f67387d to your computer and use it in GitHub Desktop.

Revisions

  1. doug4j renamed this gist Dec 29, 2018. 1 changed file with 0 additions and 0 deletions.
  2. doug4j created this gist Dec 26, 2018.
    58 changes: 58 additions & 0 deletions OmniFocus3EffortBySelectedReport.scpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    -- Modified from: http://bylr.net/3/2011/07/omnifocus-script-get-total-time-of-selected-items/

    on main()
    tell application "OmniFocus"
    tell content of first document window of front document
    --Get selection
    set totalMinutes to 0
    set validSelectedItemsList to value of (selected trees where class of its value is not folder and class of its value is not tag)
    set totalItems to count of validSelectedItemsList
    if totalItems is 0 then
    set alertName to "Error"
    set alertTitle to "Script failure"
    set alertText to "No valid task(s) selected"
    my notify(alertName, alertTitle, alertText)
    return
    end if

    --Perform action
    repeat with thisItem in validSelectedItemsList
    --display dialog "isContext " & (thisItem is context)
    --display dialog "name " & (thisItem to name of thisItem)
    set thisTaskSubTaskNum to number of tasks of thisItem

    set thisEstimate to estimated minutes of thisItem
    set thisTaskName to name of thisItem
    set thisTaskBlocked to blocked of thisItem
    set thisTaskCompleted to completed of thisItem

    --TURN on for debugging only
    --display dialog "task: '" & thisTaskName & " estimate: " & thisEstimate & " mins, " & " isBlocked: " & thisTaskBlocked & ", completed: " & thisTaskCompleted & ", subTaskCount: " & thisTaskSubTaskNum

    if thisEstimate is not missing value and thisTaskBlocked is false and thisTaskSubTaskNum is 0 and thisTaskCompleted is false then set totalMinutes to totalMinutes + thisEstimate
    end repeat
    set modMinutes to (totalMinutes mod 60)
    set totalHours to (totalMinutes div 60)
    end tell
    end tell

    --Show summary notification
    if totalItems is 1 then
    set itemSuffix to ""
    else
    set itemSuffix to "s"
    end if
    set alertName to "General"
    set alertTitle to "Script complete"
    set alertText to totalHours & "h " & modMinutes & "m total for " & totalItems & " item" & itemSuffix as string
    my notify(alertName, alertTitle, alertText)
    end main

    (* Begin notification code *)
    on notify(alertName, alertTitle, alertText)
    --Call this to show a normal notification
    tell application "OmniFocus" to display dialog alertText with icon 1 buttons {"OK"} default button "OK"
    end notify
    (* end notification code *)

    main()