AppleScript tip: how to assign text to a variable

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:


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

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.