A veces puede que necesitemos contar cuánto tiempo ha transcurrido desde un evento a otro mientras utilizamos nuestro equipo con MacOS. Con AppleScript podemos crear un script que realice esta cuenta de tiempo.
Con lo que conocemos de AppleScript y lo visto en los artículos de Crea un cronómetro de cuenta atrás en AppleScript, Controlar variables no definidas en AppleScript y Obtener la hora actual en AppleScript de distintas formas podemos crear el siguiente script:
global timeValue, counting on getTimeInSeconds() -- set t to (time of (current date)) return (time of (current date)) as number end getTimeInSeconds on startCount() set counting to true set timeValue to getTimeInSeconds() say ("Contando") end startCount on stopCount() set numberOfSeconds to getTimeInSeconds() - timeValue as integer set numberOfHours to numberOfSeconds / 3600 as integer if numberOfHours > 0 then set numberOfSeconds to numberOfSeconds - (numberOfHours * 3600) as integer end if set numberOfMinutes to numberOfSeconds / 60 as integer if numberOfMinutes > 0 then set numberOfSeconds to numberOfSeconds - (numberOfMinutes * 60) as integer end if say ("Tiempo transcurrido " & numberOfHours & " horas, " & numberOfMinutes & " minutos y " & numberOfSeconds & " segundos.") set timeValue to 0 set counting to false end stopCount on run try if counting = false then startCount else stopCount() end if on error number -2753 startCount() end try end run