The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Sum of Estimated Times Thread Tools Search this Thread Display Modes
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"
Attached Files
File Type: zip SumTimes.scpt.zip (3.7 KB, 703 views)
 
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
 
Very nice! This works great! Thank you.
 
Thanks for that so much, i'm at work at the moment but i've copied the thread name and e-mailed Landlord Insurance 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 :)

Last edited by nathan3011; 2009-02-05 at 04:53 AM..
 
This is a great script. I just found out I have 7 hours of things scheduled and 3 hours to do them!
 
Unfortunately both scripts do not work for me. The error message is: "IngTotal is not defined." :-(

Can anybody help?
 
Make sure you have selected the items you wish to sum before running the script.
 
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
 
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:
Originally Posted by mseibert View Post
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.
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

Last edited by abh19; 2009-01-09 at 06:12 AM..
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Estimated Time of Zero skillet OmniFocus 1 for Mac 2 2012-04-09 01:22 PM
Estimated Time? sirluce OmniFocus for iPad 3 2010-12-03 03:55 AM
Can OF Give Total Estimated Time? klaing OmniFocus 1 for Mac 2 2009-07-22 07:10 PM
Calculated Estimated Time on Projects bjabernethy OmniFocus 1 for Mac 2 2007-05-23 07:13 PM


All times are GMT -8. The time now is 09:17 PM.


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