Re: Dumb performance question: tell blocks
Re: Dumb performance question: tell blocks
- Subject: Re: Dumb performance question: tell blocks
- From: Jon Pugh <email@hidden>
- Date: Tue, 17 Oct 2006 08:33:26 -0700
At 9:04 AM -0400 10/17/06, Mark J. Reed wrote:
>In general, if I have a loop like this:
>
>repeat with i from 1 to N
> use an applescript builtin
> use an applescript builtin
> tell application "Foo" to do something
> use an applescript builtin
>end repeat
>
>is that going to perform better, worse, or about the same as wrapping
>the whole thing in a tell application "Foo" block? Does it depend on
>the app?
My general philosophy is simple: keep tell blocks as small as possible.
In that vein, this snippet seems sensible.
The key is that a tell block is mostly targeting, and as such only events and objects of that application need to be in the tell block. This avoids terminology conflicts and speeds up scripts by not sending superfluous events to applications which don't handle them.
Additionally, I prefer to create booleans from application properties and use those later, outside of the application's tell block to implement the script's logic.
tell app "Foo"
set hasMyWindow to exists window "Bar"
end
if hasMyWindow then
tell app "Foo"
some event
end
end
As opposed to:
tell app "Foo"
if exists window "Bar" then
some event
end
end
While the second seems simpler, it's also prone to problems later when you add functionality to it. It's also unclear which operations need to be sent to the application. The first example, while a bit clunkier in this made up example, is going to be easier and safer to modify.
Just my 2ยข.
Jon
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden