Re: text item delimiters
Re: text item delimiters
- Subject: Re: text item delimiters
- From: kai <email@hidden>
- Date: Sun, 31 Oct 2004 21:07:06 +0000
On Wed, 27 Oct 2004 21:55:54 -0400, David Andrews <email@hidden>
wrote:
So what's in a label? It seems to me that the labels given to the text
item delimiters could be misleading since they all seem to do the same
thing:
-----------------
--set text item delimiters to "1" --> {"1", "1", "1"}
--set my text item delimiters to "2" --> {"2", "2", "2"}
set AppleScript's text item delimiters to "3" --> {"3", "3", "3"}
{text item delimiters, my text item delimiters, AppleScript's text item
delimiters}
-----------------
On Thu, 28 Oct 2004 23:35:22 -0400, David Andrews <email@hidden>
wrote:
So, I can see that "scope" applies to text items delimiters, but still,
what's with the various labels?
I sense that you're not entirely convinced about this one, David - and,
as far as I can see, no further comments have been made since your most
recent question above. So, FWIW, here's a brief summary of my take on
it...
The forms shown above may seem to be/do the same in some circumstances.
However, as we've already seen, they can also produce differing results
in certain situations.
Example 1 - basic script:
In this simplest of scenarios, outside any tell statements and with no
explicit script parent property, the target of a command is the current
script. Normally, any command not understood by the current target
would be passed to its parent to be handled (or to return an error).
So, unless a script explicitly (and unusually) declared a 'text item
delimiter' property of its own, any reference to text item delimiters
would be passed to AppleScript anyway. This is really the only case in
which all three of the above forms should always produce the same
results.
Example 2 - tell statement:
When performing text operations on the fly from within, say, an
application tell statement, the term 'text item delimiters' is likely
to produce an error - unless the target application has its own text
item delimiters property (and I can't think of one that currently does,
off-hand). In tell statements, the variable 'me' is used to indicate
that the target of a command is the current script - rather than the
default target of the tell statement. So, to avoid a problem here, we
could use the phrase 'text item delimiters of me', or 'my text item
delimiters'. The command would then be handled in a similar way to that
in example 1, above.
Example 3 - tell statement and/or explicit parent property:
The 'AppleScript' "label" is actually a global variable, which can be
referred to from any part of any script - to get the properties of
AppleScript itself (rather than those of the current target). This can
also be useful in a tell statement - and even in a script where the
current application is not the default target application (if its
parent property is set to some other application, for example).
So what's the best way to refer to text item delimiters?
Usage examples offered by Apple invariably refer to the full Monty:
"AppleScript's text item delimiters" - regardless of context. This is
also the approach taken by many folk around here, for good reason: it
should always work.
Others may find the 34-character phrase a bit of a typing chore. IIRC,
it might have been one John Delacour [1] who originally espoused the
23-character "my text item delimiters" approach. This should work in
most situations, including within application tell blocks. However,
it's worth noting that it could cause a few surprises if you start
fooling around with the parent property of scripts.
There are yet others who throw caution to the wind with utterly
careless abandon - and use the minimal 20-character "text item
delimiters" whenever they think they can get away with it. Personally,
I tend to deal with TID routines in dedicated handlers, well away from
tell blocks and parent properties - so I've often been caught hanging
out with this last group of cavalier ne'er-do-wells...
So "yer pays yer money and yer takes yer choice", as the old saying
goes.
I hope that helps a little. Whether or not you still consider having a
few options misleading, I'll leave up to you - though I find the
choices and flexibility offered by AppleScript quite appealing [2]. :-)
---
kai
[1] * Seems to me that dear old JD has always had an aversion to typing
even one character more than is absolutely necessary! (Or is my memory
playing tricks here?)
[2] Nine lives:
------------------
tell {"More than one way to skin a cat", {}}
repeat with i in first item's {text -3 thru -1, word 8, text 29 thru
31, word -1, text from word -1 to -1, last word, text from last word to
end, last item of words, text end thru -3}
set end of second item to i's contents
end repeat
last item
end tell
--> {"cat", "cat", "cat", "cat", "cat", "cat", "cat", "cat", "cat"}
------------------
_______________________________________________
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