By Alvin Alexander. Last updated: May 19, 2018
A question I get frequently is “How do I assign some text (or a string) to a variable in AppleScript?” The syntax for this is as follows:
set myVar to "foo bar"
This assigns the text string "foo bar" to a variable named myVar
. A more generic way of stating this syntax is:
set YOUR_VARIABLE to "THE STRING"
If you want to verify this you can make this script a little longer, and display the variable myVar
in a dialog, like this:
set myVar to "foo bar" display dialog myVar