Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
503 views
in Technique[技术] by (71.8m points)

applescript - Is restoring text item delimiters necessary?

The commonly recommended way to use text item delimiters is like this:

set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "x"
set l to text items of "aaxbb"
set AppleScript's text item delimiters to tid
l

I usually do something like this though:

set text item delimiters to "x"
text items of "aaxbb"

http://macscripter.net/viewtopic.php?id=24725:

It is important to pay attention to the message: "ALWAYS SET THEM BACK". AppleScript remembers its delimiters setting. Even if you open a new second script in the Script Editor, the delimiters you set in the first will apply in the second.

I haven't been able to reproduce it though. Did the behavior change in some version of OS X?

AppleScript: The Definitive Guide:

The value of the text item delimiters persists as long as this instance of the AppleScript scripting component does. Because you might run more than one script in the presence of this scripting component, any of which might set the text item delimiters, it is wise to make no assumptions as to the value of the text item delimiters.

Is this still the case, or can you give any examples where the text item delimiters property affects other scripts?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I remember reading something about this change that you're talking about, that it was no longer necessary to reset them, however I couldn't find anything about it after a Google search. As such I did a quick test. I made these 2 scripts and ran them in AppleScript Editor. First this one...

set text item delimiters to "something"
return text item delimiters

And then this one...

return text item delimiters

The second script returns {""}. So it seems the first script is not affecting the second. I tested this in both 10.6 and 10.8 with the same results.

Here's applescript release notes. I can't find release notes for 10.7 or 10.8. Searching them turns up nothing on this subject either...

http://developer.apple.com/library/mac/#releasenotes/AppleScript/RN-AppleScript/RN-10_3/RN-10_3.html#//apple_ref/doc/uid/TP40000982-CH103-SW1

Therefore I have no definitive answer for you. Everyone says to reset them but my simple test shows that it's not required.

Also you're right, you don't need "Applescript's" outside of tell blocks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...