G’day
I’m automating a warning email that sends a message to the relevant IT manager if my script finds a problem with the server, that it has to send copies of emails to.
Error trapping is easy, but if i send a message with every email that arrives, he’ll be pissed!
I’d like to send one message per hour, and have come up with the attached script.
However, the way that it works, if there is a fault at, say, 2.05 on day 1, and it send messages every hour for 3 hours (till 5.05), then gets fixed, then gets a breakdown at 5.10 then next day, it will wait until another hour from 5.05 goes past, before sending the first email for that day.
Is there anything such as getting total time in seconds from a certain date, or SOMETHING that will give me a better way of keeping the time?
I’ve tried saving the current time, but it saves as gibberish unless saved as a string or text, and as a string I can’t do time comparisons.
The script does not stay open, and cannot be made to stay open, it’s a folder action generated one.
Regards
Santa
PS Sorry if I’m full of questions in this forum, but I’m learning heaps from you guys!
my seeifhourhaselapsed()
on seeifhourhaselapsed()
tell application "Finder"
set CheckLastTime to 0
set TheFileName to (path to desktop folder as string) & "DataTimeSave.dat"
set theEntireSeconds to time of (current date) -- the day time in seconds
try
set CheckLastTime to (read file (TheFileName) using delimiter ",")
end try
try
set TimeElapsed to theEntireSeconds - CheckLastTime
on error
set TimeElapsed to 3601
end try
if TimeElapsed > 3600 or (TimeElapsed > -23 * 3600 and TimeElapsed < 0) then
set fRef to (open for access file TheFileName with write permission)
set eof fRef to 0
try
write (theEntireSeconds as string) & "," to fRef
close access fRef
end try
return true
else
return false
end if
end tell
end seeifhourhaselapsed