Member
2012-06-18, 11:07 AM
Quote:
Originally Posted by whpalmer4
The problem is that you're reading that number in as a string, not a number. After that is resolved, the rest of the code doesn't work quite right, at least as I understand the goal. I've attached a version that figures out how many whole pomodori are required, plus the minutes of a fractional pomodoro, plus a 5 minute break after each full pomodoro. If it's not what you wanted, well, as my long-ago boss was fond of saying, you know where the sources are...
|
Thank you yet again whpalmer4 you have helped me out so many times! That is awesome and much cleaner than the approach I was doing. That is exactly what I was looking for and gave me the help I needed to finish the rest of it.
See the link for the finished script.
http://reference.studioprime.com/for...l_Pomodoro.zip
I hope some day I meet you so I can thank you in person. Your skills amaze and wow me! Thanks for helping me, especially when I know you aren't into tracking time like this.
In case the link gets broken here is the script.
Code:
--http://forums.omnigroup.com/showthread.php?t=9983
-- Pomodoro addition Whpalmer4 and Adam Olson, 2012-06-18
-- 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
property pFullPomodoroMinutes : 25
property pFullPomodoroBreak : 5
property pHour : 60
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
-----
--Pomodoro portion by whpalmer4 + some additional stuff.
set requestedMinutes to the clipboard as integer
set numberOfPomodoros to requestedMinutes div pFullPomodoroMinutes
set fractionalPomodoroMinutes to requestedMinutes - (numberOfPomodoros * pFullPomodoroMinutes)
set totalMinutes to numberOfPomodoros * (pFullPomodoroMinutes + pFullPomodoroBreak) + fractionalPomodoroMinutes
set pomodoroHours to totalMinutes div pHour
set pomodoroMinutes to totalMinutes - (pomodoroHours * pHour)
set totalBreakMinutes to numberOfPomodoros * pFullPomodoroBreak
set totalBreakHours to totalBreakMinutes div pHour
set fractionalBreakMinutes to totalBreakMinutes - (pHour * totalBreakHours)
---
if fractionalPomodoroMinutes = 1 then
set fractionalPomodoroMinutesPlural to " additional minute "
else
set fractionalPomodoroMinutesPlural to " additional minutes "
end if
if pomodoroHours = 1 then
set pomodoroHoursPlural to " hour "
else
set pomodoroHoursPlural to " hours "
end if
if pomodoroMinutes = 1 then
set pomodoroMinutesPlural to " minute "
else
set pomodoroMinutesPlural to " minutes "
end if
if totalBreakHours = 1 then
set totalBreakHoursPlural to " hour "
else
set totalBreakHoursPlural to " hours "
end if
if pomodoroMinutes = 1 then
set fractionalBreakMinutesPlural to " minute "
else
set fractionalBreakMinutesPlural to " minutes "
end if
---
-----
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 "Selected actions: " & lngTrees & "
" & "Total time of selected actions: " & return & lngHours & strPluralHours & lngTotal & strPluralMinutes & return & return & return & "Total pomodoro time: " & return & pomodoroHours & pomodoroHoursPlural & pomodoroMinutes & pomodoroMinutesPlural & return & return & "Total break time: " & return & totalBreakHours & totalBreakHoursPlural & fractionalBreakMinutes & fractionalBreakMinutesPlural & return & return & "Total full pomodoros: " & return & numberOfPomodoros & " +" & fractionalPomodoroMinutes & fractionalPomodoroMinutesPlural & return & 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
By the way if anyone does enable the growl function you will have to update that portion of the script since I didn't take time to update that to include the Pomodoro.
Last edited by skillet; 2012-06-19 at 10:30 AM..