Alert (Display Dialog) in AppleScript

To display an alert or dialog prompt in AppleScript is easy, once you know the command string to use. For simple scripting, such as AppleScript or VBScript, I will frequently use alert dialogs to display the contents of variables. Hmm, any other reasons for a dialog prompt? Obviously, the true intent is to provide some type of user interface/input…

display dialog the [string variable]
  buttons {"Yes", "No"}
  default button 1
  with icon 1
  giving up after [(x) seconds]

To customize this, replace [string variable] with a string in quotes or a string variable name. The buttons array will let you define the text of each button, if you wanted only an “Ok” use {“Ok”}. The default button 1 defines which button is automatically selected. Giving up after (x) seconds will close the dialog automatically if the user does not respond.

set my_variable to text returned of (display dialog the [string variable]
  buttons {"Yes", "No"}
  default button 1
  with icon 1)

The above example allows you to use a “display dialog” as a user prompt, requiring some type of input that the remaining AppleScript can then process through logic, if, select, et cetera.

As you might have imagined, there are more options available for “display dialog”, including user input (text and multiple buttons). If you want more information on the “display dialog” method, check out this article on wikibooks.

-Aaron Gilbert

About aaron

IT is not just a job but also a passion. Everything I have accomplished, both personally and professionally, has been generally entertaining, bordering on fun. Some of my projects, such as working with SharePoint Services workflow actions in Visual Studio or building a custom iSCSI SAN using the OpenSolaris, ZFS and COMSTAR, has been quite rewarding. You may think nerd...I think developing a new trend!