Now that I’ve been using ASOC for a while, I’m generally pleased with its power and with the ease in which it allows us to perform certain tasks that were a lot more complicated under AppleScript Studio. However, there are some commonly used procedures that were available under AppleScript Studio and {Apple}Script Editor which are missing in ASOC, and, IMHO, whose absence make the use of ASOC needlessly cumbersome.
It seems to me that the Apple engineers could easily have implemented helper handlers to make widely used constructs such as on idle and on open available to users who develop using ASOC. This way, if someone already has written such a handler in an AppleScript Studio or {Apple}Script Editor app, it would be much easier to port that app to the ASOC environment.
For example, if someone has an idle handler written for AppleScript Studio or {Apple}Script Editor that he or she wants to use within an ASOC app, something like the following has to be done:
script SampleAppDelegate
property parent : class "NSObject"
on applicationWillFinishLaunching_(aNotification)
my performSelector_withObject_afterDelay_("idleWrapper", missing value, 0.01)
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
return true
end applicationShouldTerminate_
on idleWrapper()
try
-- The following calls the "on idle" handler and triggers
-- an error if that handler fails, or if it returns a
-- non-numeric value:
set idleTime to (0.0 + (idle))
on error
set idleTime to missing value
end try
if (idleTime is missing value) or (idleTime <= 0.0) then
set idleTime to 30.0 -- AppleScript default for idle handler delay
end if
my performSelector_withObject_afterDelay_("idleWrapper", missing value, idleTime)
end idleWrapper
on idle
-- This is the idle handler from the former AppleScript Studio
-- or {Apple}Script Editor application. It can return a number
-- that specifies how long to wait before the next invocation.
end idle
end script
It seems to me that it would be very easy for an Apple software engineer to enhance ASOC to cause something like “idleWrapper” to be automatically called behind the scenes if on idle appears within the app delegate script of an ASOC app.
Likewise, something similar could be done if on open appears.
I’ve never seen the ASOC source code, of course, but I’m sure that I could write something into that framework which implements usable helpers for on idle, on open, etc. in less than a day, if I had access to that source code.
The presence of these helpers would not take any functionality away from ASOC. If people didn’t want to use those capabilities, they wouldn’t have to. But all the developers who have been writing AppleScript code in AppleScript Studio and {Apple}Script Editor over the years would have a much easier time porting that code to ASOC. Furthermore, since constructs like on open and on idle have been part of the AppleScript language for ages, it makes sense that they should still be usable under ASOC.
Thoughts?