View Single Post
I am trying to make a script that will total the minutes and add 5 minutes to every 25 minutes of actions. That way I can quickly total how much real time will be spent doing tasks. So for example 55 minutes of actions would be 2 pomodoro's and a total of two 5 minute breaks (10 minutes) or an hour with five minutes of extra time that didn't fit in a pomodoro.

I am stuck for some reason this won't repeat on minutes higher than 100 and I can't figure out why.

Copy into your clipboard 76 and then run this script and it works as expected.

Then copy into your clipboard 100 and run this script and you can see it doesn't repeat totalMinutes even though it is less then 25 as listed.

Code:


set totalMinutes to the clipboard

set numberOfPomodoros to 0 --We need this as our starting point, if you make this a 1 then it would always be one hour more than your total or a 2 is two hours more than your real total
repeat
	if totalMinutes < 25 then exit repeat
	set totalMinutes to totalMinutes - 25 --This subtracts the minutes each time and allows you to convert it into hours each time it loops in the next line.
	set numberOfPomodoros to numberOfPomodoros + 1 --This makes the every 25 minutes you subtracted above get converted into 1 hour and then when it loops again if it can it adds one to the new total of hours.  Pretty neat!
end repeat

set totalMinutes to the clipboard --This just takes the IngTotal that was set in the clipboard and starts fresh again with total minutes of all selected actions.

set pomodoroWithBreak to 0 --We need this as our starting point, if you make this a 1 then it would always be one hour more than your total or a 2 is two hours more than your real total
repeat
	if totalMinutes < 25 then exit repeat
	set totalMinutes to totalMinutes - 25 --This subtracts the minutes each time and allows you to convert it into hours each time it loops in the next line.
	set pomodoroWithBreak to pomodoroWithBreak + 30 --This makes the every 25 minutes you subtracted above get converted into 1 hour and then when it loops again if it can it adds one to the new total of hours.  Pretty neat!
end repeat



set pomodoroHours to 0 --We need this as our starting point, if you make this a 1 then it would always be one hour more than your total or a 2 is two hours more than your real total
repeat
	if pomodoroWithBreak < 60 then exit repeat
	set pomodoroWithBreak to pomodoroWithBreak - 60 --This subtracts the minutes of each pomodoro + the 5 minute break figured from above
	set pomodoroHours to pomodoroHours + 1 --This makes the 60 minutes you subtracted above get converted into 1 hour and then when it loops again if it can it adds one to the new total of hours.  Pretty neat!
end repeat




display dialog "Total full pomodoros : " & numberOfPomodoros & " +" & totalMinutes & " minutes extra" & return & "Total pomodoro time: " & pomodoroHours & " hours " & totalMinutes & " minutes" buttons {"OK"} default button 1
Here is the complete code of what I am trying to do. Again it works as long as the minutes don't go above 100 and I don't see why.

Code:
--http://forums.omnigroup.com/showthread.php?t=9983

-- 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
-- Bill Palmer, 2011-01-30
-- Control use of growl vs. dialog box with useGrowlPref property, gracefully handle case where growlnotify not installed.
-- Also warn if any of the included tasks did not have a duration estimate

property useGrowl : false -- set this to false if you don't (want to) use Growl
property growlNotifyPath : "/usr/local/bin/growlnotify" -- default location for growlnotify installation

tell application "OmniFocus"
	tell front document
		tell document window 1
			set oTrees to selected trees of content
			set lngTrees to count of oTrees
			set underEstimate to ""
			
			if lngTrees > 0 then
				set lngTotal to 0 --This is here so when you repeat for multiple selected actions it works
				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
						set underEstimate to "
Warning: a task had no estimated duration!"
					end if
					
					
					set lngTotal to lngTotal + lngMinutes --IngTotal now equals the total number of minutes.  This seems more complicated than it needs to be.
					--set lngTotal to lngMinutes --No need to add 0 when all you need is the number if you onlly have one selected action. Otherwise it would set the last selected action as the IngTotal
					
				end repeat
			end if
			set the clipboard to lngTotal as rich text -- This doesn't seem to be needed
		end tell
	end tell
	set lngHours to 0 --We need this as our starting point, if you make this a 1 then it would always be one hour more than your total or a 2 is two hours more than your real total
	repeat
		--IngTotal at this point is the total of all selected actions in minutes
		if lngTotal < 60 then exit repeat
		set lngTotal to lngTotal - 60 --This subtracts the minutes each time and allows you to convert it into hours each time it loops in the next line.  This leaves IngTotal with a value less then 60 which is the minutes left.
		set lngHours to lngHours + 1 --This makes the 60 minutes you subtracted above get converted into 1 hour and then when it loops again if it can it adds one to the new total of hours.  Pretty neat!
	end repeat
end tell
if lngHours = 1 then
	set strPluralHours to " hour " --These just makes the sentence read correctly
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



set totalMinutes1 to the clipboard


set totalMinutes2 to the clipboard

set numberOfPomodoros to 0 --We need this as our starting point, if you make this a 1 then it would always be one hour more than your total or a 2 is two hours more than your real total
repeat
	if totalMinutes2 < 25 then exit repeat
	set totalMinutes2 to totalMinutes2 - 25 --This subtracts the minutes each time and allows you to convert it into hours each time it loops in the next line.
	set numberOfPomodoros to numberOfPomodoros + 1 --This makes the every 25 minutes you subtracted above get converted into 1 hour and then when it loops again if it can it adds one to the new total of hours.  Pretty neat!
end repeat



set totalMinutes3 to the clipboard --This just takes the IngTotal that was set in the clipboard and starts fresh again with total minutes of all selected actions.

set pomodoroWithBreak to 0 --We need this as our starting point, if you make this a 1 then it would always be one hour more than your total or a 2 is two hours more than your real total
repeat
	if totalMinutes3 < 25 then exit repeat
	set totalMinutes3 to totalMinutes3 - 25 --This subtracts the minutes each time and allows you to convert it into hours each time it loops in the next line.
	set pomodoroWithBreak to pomodoroWithBreak + 30 --This makes the every 25 minutes you subtracted above get converted into 1 hour and then when it loops again if it can it adds one to the new total of hours.  Pretty neat!
end repeat



set pomodoroHours to 0 --We need this as our starting point, if you make this a 1 then it would always be one hour more than your total or a 2 is two hours more than your real total
repeat
	if pomodoroWithBreak < 60 then exit repeat
	set pomodoroWithBreak to pomodoroWithBreak - 60 --This subtracts the minutes of each pomodoro + the 5 minute break figured from above
	set pomodoroHours to pomodoroHours + 1 --This makes the 60 minutes you subtracted above get converted into 1 hour and then when it loops again if it can it adds one to the new total of hours.  Pretty neat!
end repeat


--set


if useGrowl then
	set fp to (POSIX file growlNotifyPath)
	tell application "Finder"
		if not (exists fp) then
			set useGrowl to false
		end if
	end tell
end if



if useGrowl then
	do shell script growlNotifyPath & " Estimated Project Time -a OmniFocus -m ' " & lngTrees & " " & strPluralTasks & "
 " & (lngHours) & "" & strPluralHours & "and " & lngTotal & "" & strPluralMinutes & underEstimate & "' "
else
	display dialog "Item count: " & lngTrees & "
" & "Total time: " & lngHours & strPluralHours & lngTotal & strPluralMinutes & return & "Total minutes: " & totalMinutes1 & return & underEstimate & return & "Total full pomodoros : " & numberOfPomodoros & " +" & totalMinutes2 & " minutes extra" & return & "Total pomodoro time: " & pomodoroHours & " hours " & totalMinutes3 & " minutes" buttons {"OK"} default button 1
	
	(*I don't understand why they need the parenthesis around IngHours it doesn't seem to make a difference so I took it out above since it seemed confusing
		display dialog "Item count: " & lngTrees & "
		" & "Total time: " & (lngHours) & strPluralHours & lngTotal & strPluralMinutes & return & "Total minutes: " & totalMinutes & return & underEstimate buttons {"OK"} default button 1
	*)
	
	
	
	(*
	This is how I would do it but they are just putting returns in the quotes above which is another way I didn't realize you could do until today 2012-06-13
		display dialog "Item count: " & lngTrees & return & "Total time: " & (lngHours) & strPluralHours & lngTotal & strPluralMinutes & return & underEstimate buttons {"OK"} default button 1
	*)
	
end if

--IngTrees = Number of tasks selected
--IngHours = Total hours of selected tasks
--IngTotal = Total minutes of selected tasks
--Cli

(*

This is an example of how to set the contents of the clipboard and also set the clipboard to a variable. http://macscripter.net/viewtopic.php?id=8396
	set myString to "Hello There!"
	set the clipboard to myString -- This is how you set the clipboard to a name so you can use that value.
	set myClipboard to the clipboard
*)

Last edited by skillet; 2012-06-18 at 05:35 AM..