I don’t understand why this code compiles in Script Editor
set mark1 to my GetTick_Now()
repeat nrepeats times
set theFileExists to FileExists(theFile)
end repeat
set mark2 to my GetTick_Now()
on FileExists(theFile) -- (String) as Boolean
set theFileExists to (do shell script "[ -e " & quoted form of theFile & " ] && echo true || echo false") as boolean
return theFileExists
end FileExists
on GetTick_Now()
## From MacScripter Author "Jean.O.matiC"
## returns duration in seconds since machine start, calculated using ticks
script GetTick
use framework "Foundation" --> for more precise timing calculations
on Now()
return (current application's NSDate's timeIntervalSinceReferenceDate) as real
end Now
end script
return GetTick's Now()
end GetTick_Now
and this will not compile. The order of the two handlers is reversed and now Script Editor doesn’t recgonise “do shell script”
set mark1 to my GetTick_Now()
repeat nrepeats times
set theFileExists to FileExists(theFile)
end repeat
set mark2 to my GetTick_Now()
on GetTick_Now()
## From MacScripter Author "Jean.O.matiC"
## returns duration in seconds since machine start, calculated using ticks
script GetTick
use framework "Foundation" --> for more precise timing calculations
on Now()
return (current application's NSDate's timeIntervalSinceReferenceDate) as real
end Now
end script
return GetTick's Now()
end GetTick_Now
on FileExists(theFile) -- (String) as Boolean
set theFileExists to (do shell script "[ -e " & quoted form of theFile & " ] && echo true || echo false") as boolean
return theFileExists
end FileExists
Commenting out the line "use framework “Foundation” " removes the compile problem, but obviously results in not runnable code.
Can anyone provide a hint why this is so?
I had thought that the Framework would be either be used for the entire parent script, or only for the entire child script, but there is some before-after dependency that I don’t understand
An obvious work around is to always put the GetTick_Now() handler at the bottom of the scrript, but I’d like to understand why.