Add text to string in Applescript

Concatenation in AppleScript doesn't seem to make it easy to add text to a string variable. I have the following line that will work in most other languages:

repeat with thisRecpt in recipients of eachMessage set recp to recp & "," & address of thisRecpt end repeat 

From what I can say, this does not seem to work in AppleScript, since you cannot use the recp variable inside the same line. Is there an easier way to add text to the end of a variable without using two variables in a loop?

Thanks!

+4
source share
1 answer

The code you posted works fine while recp first installed, say "" . However, you will get , as the first character in your string, which is probably not what you want.

Instead, you can do this:

 set _delimiters to AppleScript text item delimiters set AppleScript text item delimiters to "," set recp to eachMessage recipient address as string set AppleScript text item delimiters to _delimiters 

Yes, this is ugly, but it is more efficient, and you only get "," between addresses.

+3
source

All Articles