Tuesday, March 19, 2019

#1 2019-01-08 08:29:52 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 53

Single versus Multiple Tell Statements

When writing an AppleScript, I am often presented with the following options and I'm never sure which way to go:

1) Have one application tell statement (typically Finder or System Events) and include within that tell statement code that does not require the application.

2) Have multiple application tell statements (all of which call the same application) and do not include within the tell statement any code that does not require the application.

I wondered if either of these options is faster or better in some way.

BTW, the term, "code that does not require the application", refers to simple stuff like looping through a list of 10 or so items to find a match. Also, I understand that this question in the abstract is difficult to answer but I thought an experienced forum member might have some general rule that he/she follows.

Thanks.

Last edited by peavine (2019-01-08 10:13:42 am)

Offline

 

#2 2019-01-08 05:27:20 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 855

Re: Single versus Multiple Tell Statements

This is a personal style issue with some caveats. Keeping commands within a single tell block is fine, as long as (1) code therein doesn’t explicitly belong within another’s scope—e.g. standard additions; (2) the addressed application isn’t already busy or hung—e.g. Finder is performing a transfer; (3) it decreases your overall code length, thereby improving legibility.

Offline

 

#3 2019-01-09 07:32:55 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 53

Re: Single versus Multiple Tell Statements

Thanks for the response Marc Anthony. I guess I had it in my mind that multiple tell statements calling a particular application would start and stop the application each time, slowing down the script. It's good to have the flexibility to do this either way.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)