RE: Scripting Additions Calls in Tell Blocks
RE: Scripting Additions Calls in Tell Blocks
- Subject: RE: Scripting Additions Calls in Tell Blocks
- From: "Scott Norton" <email@hidden>
- Date: Tue, 10 Feb 2004 00:25:31 -0500
- Thread-topic: applescript-users digest, Vol 3 #2416 - 16 msgs
On Mon, 09 Feb 2004 23:32:36 -0500, Gary Lists <email@hidden> noted,
>
I gave a quick look at ASTDG, and beginning on page 333 there is some
>
related discussion [1].
>
>
The author points out:
>
>
"One of the main reasons for using scripting additions is speed [over
>
straight AS code]." and
>
>
"Just how quickly a scripting addition is called though, depends on how you
>
call it. The osax architecture is such that a scripting addition appears to
>
be present 'inside' whatever application is being targeted when the
>
scripting addition command is called."
>
>
He goes on to describe the slow-down, with the command being dealt with
>
(unsuccessfully) by the targeted application and then being passed along
>
when no entry is found in the dictionary.
The delay is mostly due to the overhead switching the foreground application.
The application doesn't takes a long time to determine that it doesn't know how to handle the message--that's just a table lookup. But that the computer must switch the active application from Script Editor or the applet shell, into the targeted application. This is very slow (like 400 milliseconds). Calling an OSAX is 10 times faster, while executing one line of AppleScript is 10 times faster than that (if I correctly remember some timing tests I ran some time ago.) Note came from testing under OS 9. I imagine native OS X code switches more efficiently.
So, an OSAX that does the equivilent work of 10 lines of AppleScript (or one line executed 10 times in a loop) is worth the trouble. Telling an application to do anything will slow you down by noticable amounts (400 milliseconds is 15 dog-years in computer time.)
Of course, telling an application is the whole point of most AppleScripts. In that case, you grit you teeth and don't worry about the overhead. If you are calling an OSAX inside an application tell block, you can avoid the overhead by surrounding the OSAX call with "tell me to ..."
Sometimes you might want the OSAX to be executed by the targeted application. For example, "display dialog" in an application tell block will pop up the display under that application--useful for folder actions and droplets.
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.