2

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?

Lri
  • 26,768
  • 8
  • 84
  • 82

4 Answers4

3

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.

regulus6633
  • 18,848
  • 5
  • 41
  • 49
3

I found this tidbit on https://developer.apple.com/library/mac/#documentation/applescript/conceptual/applescriptlangguide/conceptual/ASLR_fundamentals.html in the section AppleScript Fundamentals > Global Constants in AppleScript > text item delimiters:


If you change the text item delimiters property in Script Editor, it remains changed until you restore its previous value or until you quit Script Editor and launch it again. If you change text item delimiters in a script application, it remains changed in that application until you restore its previous value or until the script application quits; however, the delimiters are not changed in Script Editor or in other script applications you run.


user1002119
  • 3,692
  • 4
  • 27
  • 30
  • I still can't reproduce it, or I'm interpreting it the wrong way. If the behavior changed at some point, it's possible that AppleScript Language Guide hasn't been updated to reflect the change. – Lri Jul 20 '13 at 06:17
0

If you run a script application, then I guess technically it is not necessary to rest them, because once it has quit, it has quit!

But if you are running the script in Script Editor, then the changes to delimiters will stay in that script in the script editor. I've just seen that today.

But what changed some years back is that it does NOT affect other scripts / windows open in Script Editor.

Also, when running as an application, it only affects that particular script.

Nic
  • 88
  • 5
0

It's not about whether the AppleScript's text item delimiters change affects other scripts or not, but that the change affects the entire script where you do it.

In a large script with a lot of handlers, it's very hard to keep track of and it is easy to forget that this change is still in effect, and this can lead to you having to spend a lot of time and painstakingly looking for where the hidden error has crept in.

Therefore, my answer to the question (for those who want to write easy-to-debug scripts and script libraries) is this: - just in case, always restore the original AppleScript's text item delimiters, since this is a global property.

Robert Kniazidis
  • 1,760
  • 1
  • 7
  • 8