Re: Crashing Script
Re: Crashing Script
- Subject: Re: Crashing Script
- From: Steve Mills <email@hidden>
- Date: Fri, 12 Feb 2016 17:11:23 +0000 (GMT)
On Feb 12, 2016, at 10:54 AM, "Stockly, Ed" <email@hidden> wrote:
I have two problems with this script. The first is that if I uncomment the log command it crashes Script Editor (but not script debugger).
The second problem (which is why I’m using SE on it in the first place and why I’m logging commands) is that the results are whacked.
The main handler builds a list that contains an appleScript date with a random time; and a text representation of that time.
{date "Friday, February 12, 2016 at 3:40:16 am", "3:40 a.m.”} — for example.
Stepping through in SD, I can tell that the date and the text in the timePair variable match.
But when the timeList is returned at the end, none of the pairs match. When I comment out the log command in SE I get the same result.
So, does this script crash anyone else’s script editor?
Does anyone else get the same match, then mismatch I get?
And, why?
----------------------
set myTime to current date
set secsInADay to (24 * 60 * 60)
set timeList to {}
repeat 100 times
set newTime to myTime
set time of newTime to random number from 1 to secsInADay
newTime
set TimeAsText to my DateToTimeText(newTime)
set timePair to {newTime, TimeAsText}
--log timePair
set the end of timeList to timePair
end repeat
return timeList
on DateToTimeText(anyTime)
set {theHour, theMinute} to {hours of anyTime, minutes of anyTime}
if theHour > 12 then
set theHour to theHour - 12
set amOrPm to " p.m."
else
set amOrPm to " a.m."
end if
if theMinute is 0 then
set thisTime to (theHour as text) & amOrPm
else
if theMinute < 10 then
set theMinute to "0" & (theMinute as text)
else
set theMinute to (theMinute as text)
end if
set thisTime to (theHour as text) & ":" & theMinute & amOrPm
end if
return thisTime
end DateToTimeText
Curiously, each record in the resulting list has the same time in the 1st item (newTime). The variable newTime is being shared among each record, as if it were ref counted. Why is that? If I change "set newTime to myTime" to "copy myTime to newTime", it works as I'd expect.
BTW, it doesn't crash for me on 10.10.2, even with the log command left in.
Sent from iCloud's ridiculous UI, so, sorry about the formatting
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden