View Single Post
Thanks for the great script. I've been looking for something just like this. I modified the script slightly to change the output back to an improved Growl Notification. There are still two modifications I'd like to make:

1. Automatically insert the estimate time into the project or group.
2. In a project with several groups, I would like the script to calculate the estimated time for the project based on the group estimated times and not the group plus action estimated times. Currently, if you run the script on a group, then run the script on a whole project, it will return a result that is twice your intended result.

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.
-- Ben Davidson (benjamin@idavidson.ca), 20009-05-02
-- Updated the Growl notification feature and removed the dialogue box (you need to install the Growl extra, "growlnotify" - included in the install disk image)
-- Changed some of the dialog wording
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
					
				end repeat
			end if
			set the clipboard to lngTotal as rich text
			-- do shell script "/usr/local/bin/growlnotify OmniFocus  -m 'Total time " & lngTotal & " minutes' -p 1"
		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
if lngTrees = 1 then
	set strPluralTasks to "task"
else
	set strPluralTasks to "tasks"
end if

do shell script "/usr/local/bin/growlnotify Estimated Project Time -a OmniFocus -m ' " & lngTrees & " " & strPluralTasks & "
 " & (lngHours) & "" & strPluralHours & "and " & lngTotal & "" & strPluralMinutes & "' "