Hi kamil,
I rewrote the stopwatch with pause if you’re interested. Was on a little medication, because of a bad cold.
Anyway, here’s an example of stopwatch with pause using the reopen handler:
global run_time, is_running, start_date
-- initialize
on run
set run_time to 0
set is_running to false
reopen
end run
-- reopen to toggle pause
on reopen
set is_running to not is_running
set cur_date to current date
if is_running then -- set start date
-- start or reset start date
set start_date to cur_date
say "running" without waiting until completion
else -- pause (add to total time)
set run_time to run_time + (cur_date - start_date)
say "paused" without waiting until completion
end if
end reopen
on quit
-- display total run time without the pauses
set cur_date to current date
set run_time to run_time + (cur_date - start_date)
try -- trap error bug if user cancel dialog
display dialog "" & run_time & " secs"
end try
continue quit
end quit
You can run this with another AppleScript or Service using a keyboard shortcut or just rerun.
Edited: there’s still a bug if the user quits when it’s paused. Working on that and thinking of the best way to integrate this without an overall timer. I think I have one in the list somewhere, but can’t find it.
Edited: quick fix. Check if it was running or paused in the quit handler:
global run_time, is_running, start_date
-- initialize
on run
set run_time to 0
set is_running to false
reopen
end run
-- reopen to toggle pause
on reopen
set is_running to not is_running
set cur_date to current date
if is_running then -- set start date
-- start or reset start date
set start_date to cur_date
say "running" without waiting until completion
else -- pause (add to total time)
set run_time to run_time + (cur_date - start_date)
say "paused" without waiting until completion
end if
end reopen
on quit
-- display total run time without the pauses
set cur_date to current date
if is_running then
set run_time to run_time + (cur_date - start_date)
end if
try -- trap error bug if user cancel dialog
display dialog "" & run_time & " secs"
end try
continue quit
end quit
Still might need testing.
Edited: didn’t need to get the current date if it was paused:
global run_time, is_running, start_date
-- initialize
on run
set run_time to 0
set is_running to false
reopen
end run
-- reopen to toggle pause
on reopen
set is_running to not is_running
set cur_date to current date
if is_running then -- set start date
-- start or reset start date
set start_date to cur_date
say "running" without waiting until completion
else -- pause (add to total time)
set run_time to run_time + (cur_date - start_date)
say "paused" without waiting until completion
end if
end reopen
on quit
-- display total run time without the pauses
if is_running then
set cur_date to current date
set run_time to run_time + (cur_date - start_date)
end if
try -- trap error bug if user cancel dialog
display dialog "" & run_time & " secs"
end try
continue quit
end quit
gl,
kel