AppleScript tip: how to concatenate strings

By Alvin J. Alexander, devdaily.com

A frequent question is "How do I combine (or concatenate) strings in AppleScript?" Fortunately this is pretty easy in AppleScript, you just use the ampersand (&) operator. Here are a few examples, with dialogs thrown in so you can see the result:

set myVar to "Al " & "was " & "here."
display dialog myVar

Here's a slightly more complicated example, using variables for each string:

set a to "Al "
set b to "was "
set c to "here."
set myVar to a & b & c
display dialog myVar

To test these, just copy them into your ScriptEditor, and press the Run button. (The ScriptEditor is in the Applications::AppleScript folder.)


devdaily logo