Bizarre behavior in Applescript vs. Applescript Studio

I wrote a script in AppleScript using OS X’s Script Editor. Everything worked fine. But then I copied and pasted my script into an AppleScript Studio app and whenever I ran it I got some strange results. For some reason my script was being run differently in AS and ASS but I couldn’t figure out why–it was the exact same script! So I finally traced the problem to the way lists are coerced to strings. Take a look:

--In Script Editor:
{"hello","there"} as string
--"hello,there"

--In AppleScript Studio:
{"hello","there"} as string
--"hellothere"

Which is the correct behavior? I need it done the first way, but in AppleScript Studio. Does anyone have any recommendations?

Er, that’s not what you should get. The default should be “hellothere” (in either application) unless you’ve been using text item delimiters.

Yeah, sorry :confused:

I didn’t know what text item delimiters did so I was playing around with them and apparently they don’t get reset until you quit the script editor. Well, now I know what they do at least. Thanks for the help with the stupid question.

You should “save” the current delimiter, and then “restore” it when you’re done.

set testList to {"hello", "there"}

set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
set testString to testList as text
set AppleScript's text item delimiters to ASTID

return testString

Technically speaking, applescript’s text item delimiters should be declared as a list, not as a string. Setting delimiters as a string value will still compile, but for sakes of proper syntax and future compatibility you should declare them in list format.

So, you should change the line declaring your tid’s from…

set AppleScript's text item delimiters to ","

…to…

set AppleScript's text item delimiters to {","}

j