I created one start to log a "start time" and save into a plist file, and a an other script to read the start time and calculate the number of time elapsed from the start time and now (reading time)

first script (log time in plist) :

set myDate to date string of (current date)
set [dayLetter, dayNumber, MonthLetter, yearNumber] to the words of myDate
set t to (time string of (current date))
set [hoursInNumber, minutesInNumber, secondInNumber] to the words of t

set startTimeValue to (current date)
set startTimeClear to dayLetter & " " & dayNumber & " " & MonthLetter & " at " & hoursInNumber & ":" & minutesInNumber

set plistR to {startTime:startTimeValue, startTimeClear:startTimeClear}
tell application "System Events"
    set plistf to make new property list file ¬
        with properties {name:"~/Desktop/myTime.plist"}
    set plistf's value to plistR
end tell

second script (read plist)

set NowTimeValue to (current date)
set the plistfile_path to "~/Desktop/myTime.plist"
tell application "System Events"
    set p_list to property list file (plistfile_path)
    -- read the plist data
    set startTimeValue to value of property list item "startTime" of p_list
end tell
set Elapsed to startTimeValue - NowTimeValue

the main issue is, the time given is in second, and if I try yo divid by 60 that give me an hour.

how can I get this time in minutes / hours instead?


Never-mind find the solution :

set Elapsed to (startTimeValue - NowTimeValue as number) / 60
  • although how can I only keep two decimal? – Kevin Mar 21 '19 at 20:48
  • set x to (round (x * 100)) / 100 – CJK Apr 17 '19 at 20:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .