The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Sum of Estimated Times (http://forums.omnigroup.com/showthread.php?t=9983)

JakeB 2008-09-24 08:05 AM

Sum of Estimated Times
 
1 Attachment(s)
Hi All,

Thanks to the previous expertise displayed in these forums, I've cobbled together an applescript to sum up the estimated times of the actions for a given project. Of course, it would be nice to associate this script with the cell for estimated time for a given project (so that it would sum up the times of the child actions), but for now, at least, if you select some actions, it will sum the estimated times, display the result in Growl, and also put the result on the clipboard (so you can paste it into the overall project estimated time cell).

As you can see, I said "cobbled" above because I relied entirely on the great work of RobTrew and a11en in other threads.

If anyone knows how to more automagically associate this with the cells of the projects which own the actions so more directly do something like inserting =sum() into the estimated time cell for a project, I'd love to hear about it!

And of course, improvements, changes, etc.. are very welcome!

I'm including the script as an attachment and am also just pasting in the text.

Thanks again to you all!

Jake

Here it is:
[CODE]-- Sum estimated times, display sum in Growl and copy sum to clipboard (for later pasting back into estimated time for an entire project, or elsewhere).
-- Jake Bowers (jwb1970@gmail.com), 2008-24-10
-- largely based on RobTrew's StartTimer.scpt Ver 0.02 for code to adds up durations of selected tasks (http://forums.omnigroup.com/showthread.php?t=4748)
-- and on hint from a11en in thread Minuteur Applescript for Growl Notification. (http://forums.omnigroup.com/showthread.php?t=6749)

tell application "OmniFocus"
tell front document
tell document window 1
set oTrees to selected trees of content
set lngTrees to count of oTrees

if lngTrees > 0 then
set lngTotal to 0
repeat with iTree from 1 to lngTrees
set oTask to value of (item iTree of oTrees)

set lngMinutes to estimated minutes of oTask
-- set lngMinutes to 0 if duration is empty
try
lngMinutes
on error
set lngMinutes to 0
end try

set lngTotal to lngTotal + lngMinutes
--do shell script "/usr/local/bin/growlnotify OmniFocus -m 'Total time " & lngTotal & " minutes' -p 1"
end repeat
end if
end tell
end tell
set the clipboard to (lngTotal / 60) as rich text
--set the clipboard to (the clipboard) & return & lngTotal
end tell

do shell script "/usr/local/bin/growlnotify OmniFocus -m 'Total time " & (lngTotal / 60) & " hours' -p 1"[/CODE]

refulgentis 2008-11-08 12:01 AM

thanks for this script, I've been using it a lot.
I modified a couple things that didn't work for me:
-- added loop so the task durations would display as, say, 3 hours 15 minutes instead of just 3.25
--display a dialog box with the total time now instead of copying to the clipboard, also the number of items selected is shown
-- handle the sort "boxes" in context view so I can just select all and have it display the total estimated time for all my actions


modified version:
[code]-- Sum estimated times, display sum in Growl and copy sum to clipboard (for later pasting back into estimated time for an entire project, or elsewhere).
-- Jake Bowers (jwb1970@gmail.com), 2008-24-10
-- largely based on RobTrew's StartTimer.scpt Ver 0.02 for code to adds up durations of selected tasks (http://forums.omnigroup.com/showthread.php?t=4748)
-- and on hint from a11en in thread Minuteur Applescript for Growl Notification. (http://forums.omnigroup.com/showthread.php?t=6749)
-- James O'Leary (jpo@me.com), 2008-08-11
-- now can handle context view "boxes) (assigned an estimated time of 0) and the time displayed is in hours and minutes instead of
-- just a straight up hours number. Displays in dialog box now instead of copying to clipboard. Item count displayed as well.
tell application "OmniFocus"
tell front document
tell document window 1
set oTrees to selected trees of content
set lngTrees to count of oTrees

if lngTrees > 0 then
set lngTotal to 0
repeat with iTree from 1 to lngTrees
set oTask to value of (item iTree of oTrees)


try
set lngMinutes to estimated minutes of oTask
on error
set lngMinutes to 0
end try

if lngMinutes as string is equal to "missing value" then
set lngMinutes to 0
end if


set lngTotal to lngTotal + lngMinutes
--do shell script "/usr/local/bin/growlnotify OmniFocus -m 'Total time " & lngTotal & " minutes' -p 1"
end repeat
end if
end tell
end tell
set lngHours to 0
repeat
if lngTotal < 60 then exit repeat
set lngTotal to lngTotal - 60
set lngHours to lngHours + 1
end repeat
end tell
if lngHours = 1 then
set strPluralHours to " hour "
else
set strPluralHours to " hours "
end if
if lngMinutes = 1 then
set strPluralMinutes to " minute."
else
set strPluralMinutes to " minutes."
end if

display dialog "Item count: " & lngTrees & "
" & "Total time: " & (lngHours) & strPluralHours & lngTotal & strPluralMinutes


[/code]

ngilmore031 2008-11-18 07:47 AM

Very nice! This works great! Thank you.

nathan3011 2008-12-19 04:38 AM

Thanks for that so much, i'm at work at the moment but i've copied the thread name and e-mailed [URL="http://www.landlordinsurance.org.uk/"]Landlord Insurance[/URL] across to my home e-mail so that i can see if this works and if so i'll post back here if it worked :-)

I'll play around with it over the weekend and hopefully it will all work ok :)

gcrump 2008-12-20 07:58 AM

This is a great script. I just found out I have 7 hours of things scheduled and 3 hours to do them!

mseibert 2008-12-27 03:59 AM

Unfortunately both scripts do not work for me. The error message is: "IngTotal is not defined." :-(

Can anybody help?

Gerocrack 2009-01-06 08:22 PM

Make sure you have selected the items you wish to sum before running the script.

abh19 2009-01-08 05:01 AM

If anybody's interested, I made two minor changes to the (modified) script:

1) removed the "cancel" button from the dialog because it's not necessary (plus, clicking it gives an error)

2) the total time (in minutes) is added to the clipboard. When pasted into omnifocus, this number takes the appearance of "__h __m" like you'd expect

[CODE]-- Sum estimated times, display sum in Growl and copy sum to clipboard (for later pasting back into estimated time for an entire project, or elsewhere).
-- Jake Bowers (jwb1970@gmail.com), 2008-24-10
-- largely based on RobTrew's StartTimer.scpt Ver 0.02 for code to adds up durations of selected tasks (http://forums.omnigroup.com/showthread.php?t=4748)
-- and on hint from a11en in thread Minuteur Applescript for Growl Notification. (http://forums.omnigroup.com/showthread.php?t=6749)
-- James O'Leary (jpo@me.com), 2008-08-11
-- now can handle context view "boxes) (assigned an estimated time of 0) and the time displayed is in hours and minutes instead of
-- just a straight up hours number. Displays in dialog box now instead of copying to clipboard. Item count displayed as well.
-- Aaron Hunyady (aaron@hunyady.net), 2009-08-01
-- Removed "cancel" button in dialog. Total time in minutes is copied to the clipboard.
tell application "OmniFocus"
tell front document
tell document window 1
set oTrees to selected trees of content
set lngTrees to count of oTrees

if lngTrees > 0 then
set lngTotal to 0
repeat with iTree from 1 to lngTrees
set oTask to value of (item iTree of oTrees)


try
set lngMinutes to estimated minutes of oTask
on error
set lngMinutes to 0
end try

if lngMinutes as string is equal to "missing value" then
set lngMinutes to 0
end if


set lngTotal to lngTotal + lngMinutes
--do shell script "/usr/local/bin/growlnotify OmniFocus -m 'Total time " & lngTotal & " minutes' -p 1"
end repeat
end if
set the clipboard to lngTotal as rich text
end tell
end tell
set lngHours to 0
repeat
if lngTotal < 60 then exit repeat
set lngTotal to lngTotal - 60
set lngHours to lngHours + 1
end repeat
end tell
if lngHours = 1 then
set strPluralHours to " hour "
else
set strPluralHours to " hours "
end if
if lngMinutes = 1 then
set strPluralMinutes to " minute."
else
set strPluralMinutes to " minutes."
end if

display dialog "Item count: " & lngTrees & "
" & "Total time: " & (lngHours) & strPluralHours & lngTotal & strPluralMinutes buttons {"OK"} default button 1
[/CODE]

mseibert 2009-01-08 05:21 AM

Finally that works also on my OmniFocus-Implementation. Now I would like to pull up the Popup with a keystroke. Can anybody tell me how to do that.

abh19 2009-01-09 06:10 AM

[QUOTE=mseibert;53340]Finally that works also on my OmniFocus-Implementation. Now I would like to pull up the Popup with a keystroke. Can anybody tell me how to do that.[/QUOTE]

Instead of a hot-key trigger, you can put scripts in the OmniFocus toolbar. That would put you one click away from the script. (This is what I have set up.) To do that, rename your script file to something short, like "∑Time" (that's the math symbol for sum, btw), then copy the script file to the HD/Library/Scripts/Applications/OmniFocus/ folder. If the folder doesn't exist yet, I think you can just create it. Then go to OmniFocus and right click (or control click) on the toolbar, and choose "Customize Toolbar". Find the icon that says "Script: ∑Time" and drag it to the toolbar. Click Done. Now, you should be able to select actions and get the pop up with one click.

If you REALLY want to use a hot key trigger: first, open the script in Script Editor, choose Save As and choose File Format: Application, check Run Only, and uncheck Startup Screen. Unless I'm missing something, you'll also need a program that allows you to set F-Keys or keystrokes for items. I use DragThing for its versatile docks and the keyboard shortcuts. Any item that is in a dock can have an attached keyboard shortcut (these can be just about anything you want, such as f-keys, cmd-opt-shift-t). There are free solutions as well, which you can find on macupdate or versiontracker.

Running the script from your OmniFocus toolbar is a more elegant solution. It's also faster; running the script as an application takes a lot longer than running it as a simple script.

Hope that helps!
Aaron


All times are GMT -8. The time now is 06:59 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.