Hi There Scripters,
I would like to be able to track or record how long I’m working on a specific job. Such a job can consist of many different applications running all at the same time. It’s not necessary to track which app is running, it’s just the time in total I need to keep an eye on.
Can you help me with:
1: a small dialog box where I can fill out the name (e.g. 1234AABB-blahblah) of the file I’m working on and a ‘start’ button
2: a ‘stop’ (and perhaps a ‘pause’-‘continue’ option) button that I must click to make it happen (so if I need to pee, I can set it to wait in case the wizz takes a bit longer than expected ;))
3: a timer or overview that will give me the time spent on the job with the name, if possible rounded off to 5 minutes out of 60.
(e.g. You’ve worked 1 hour and 25 minutes on file 1234AABB-blahblah)
I’ve been fiddling with various timers, but I’m too much of a novice to get it working sorry…
Help is much much appreciated! It’s for macs with both 10.3 as well as 10.4
Hi Elsa,
give this code a try, at the moment you can only pause once but if this is what you require then I’ll work on making it be able do more than one pause.
repeat
set the_job to display dialog "Enter job ref and click OK to start timer" default answer ""
set the_job to text returned of the_job
set timeThen to current date
set user_response to display dialog "click OK to stop timer" buttons {"Pause", "OK"} giving up after 86400
set user_response to button returned of user_response
if user_response = "OK" then
--giving up after 24 hours
set timeDiff to (current date) - timeThen
--timeDiff is seconds elapsed. Set into Hrs, Mins & Secs
set hrDiff to timeDiff div 3600
set timeDiff to timeDiff mod 3600
set minDiff to timeDiff div 60
set secDiff to timeDiff mod 60
--display result
display dialog "Time elapsed" & return & hrDiff & " Hours " & minDiff & " Minutes " & secDiff & " Seconds" & return & "For job: " & the_job
else if user_response = "Pause" then
set pausetimediff to (current date) - timeThen
display dialog "Press Resume to continue timing" buttons {"Resume"} default button "Resume"
set newtimeThen to current date
set user_response to display dialog "click OK to stop timer" buttons {"Pause", "OK"} giving up after 86400
set user_response to button returned of user_response
if user_response = "OK" then
set newtimeDiff to (current date) - newtimeThen
set grandtotal to timeDiff + newtimeDiff
set hrDiff to grandtotal div 3600
set timeDiff to grandtotal mod 3600
set minDiff to grandtotal div 60
set secDiff to grandtotal mod 60
--display result
display dialog "Time elapsed" & return & hrDiff & " Hours " & minDiff & " Minutes " & secDiff & " Seconds" & return & "For job: " & the_job
end if
end if
end repeat
Thanks Stefan, this is just excellent. I found a link to Work Timer earlier (when I skimmed through older posts in order to find what I was looking for, but the link was dead. (the post dated back to 2002 or something so that might have been the reason; I assumed it had ceased to exist all together!)
Vielen Dank!
Ow Wow Blend, thank you! I didn’t see this post before Stefans! I’ll try it out right away. Thank you so much! It works beautifully. I can use both your and WorkTimer settings. Great stuff, thanks for helping out!
I have an Appleworks spreadsheet set up with columns
Date, Job, Start time, End time, Total time with total time in SS figured with formula
I then wrote this script to enter in the times for me with some help from others
global theTime
global theDate
global mypath
--Get todays date & Time
set myDate to current date
--get Date format like 08/09/06
set theDate to characters -2 thru -1 of ("0" & (month of myDate as number)) & "/" & characters -2 thru -1 of ("0" & (day of myDate as number)) & "/" & characters -2 thru -1 of ("0" & (year of myDate as number)) as string
--Get Time in 24 hour format
set myhour to (hours of myDate)
set mymin to (minutes of myDate)
--I added this part to get the leading zero in minutes
if (mymin as number) < 10 then
set mymin to "0" & mymin
else
set mymin to (minutes of myDate)
end if
set theTime to myhour & ":" & mymin as string
set mypath to "Path:to:your:WorkTimeLog.cwk"
display dialog "Enter Next Job" & return & " or End if done for the day" default answer "New Job" buttons {"Cancel", "End", "Start"} default button 3 with icon note
if button returned of the result is "Start" then
set job to text returned of the result
tell application "AppleWorks 6"
activate
open file mypath
delay 2
tell spreadsheet of front document
set row_Count to count rows
set ColumnA to column 1
-- set ColumnB to column 4
set empty_Cell_Index to 0
repeat with i from 1 to row_Count
if ((item i of ColumnA) = "") then
set empty_Cell_Index to i
exit repeat
end if
end repeat
if (empty_Cell_Index = 0) then error "No empty cell found" number 8000
-- Enter my data into SS
set data_List to {theDate, job, theTime}
repeat with i from 1 to count data_List
set cell (empty_Cell_Index + row_Count * (i - 1)) to (item i of data_List)
end repeat
-- SEE IF END TIME IS BLANK IF IS THEN ENTER TIME
set EndCell to "D" & (empty_Cell_Index - 1)
select cell EndCell
set endTime to selection
if endTime is "" then tell application "System Events"
keystroke theTime
keystroke return
end tell
end tell
delay 3
close front window saving yes
end tell
-- if BUTTON PRESSED IS End --
else
if button returned of the result is "End" then
tell application "AppleWorks 6"
activate
open file mypath
delay 2
tell spreadsheet of front document
set ColumnB to column 4
set row_Count to count rows
set empty_Cell_Index to 0
repeat with i from 1 to row_Count
if ((item i of ColumnB) = "") then
set empty_Cell_Index to i
exit repeat
end if
end repeat
if (empty_Cell_Index = 0) then error "No empty cell found" number 8000
-- Enter my data into SS
select cell empty_Cell_Index
tell application "System Events"
repeat 3 times
keystroke tab
end repeat
keystroke theTime
keystroke return
end tell
end tell
delay 3
close front window saving yes
end tell
end if
end if