answer
Syntax
answer <prompt> [with <button1> [or <button2> [or <button3>]]]
answer {file|folder} <prompt> [of type <fileNameSuffix>] [with <startPath>]
answer "Are you happy" with "No" or "Yes"
answer file "Choose a project:" of type ".xstk"
answer folder "Choose your Pixelmator folder:" with "/Applications/Pixelmator"
Explanation
The answer
command displays various modal dialogs that halt your script until
the user has finished with them.
The simple form of answer
displays a text prompt in a dialog window, with up
to 3 buttons the user can choose from. When the user clicks one of the buttons,
the dialog window closes, and the name of the button clicked will be stored in
the variable it
.
The answer file
form of the command shows a file picker dialog for selecting
a file on the user’s hard disk (or mounted servers, or anything else that would
usually be listed in a file picker). The search path for the clicked file will
be written to the variable it
. the result
will be set to the name of the
button that was clicked to close the dialog (either OK
or Cancel
).
The answer folder
form of the command shows a folder picker dialog for selecting
a folder on the user’s hard disk (or mounted servers, or anything else that would
usually be listed in a file picker). The search path for the clicked folder will
be written to the variable it
. the result
will be set to the name of the
button that was clicked to close the dialog (either OK
or Cancel
).
prompt
The message to show at the top of the dialog window, informing the user what to do.
button1, button2, button3
The names for up to 3 buttons to be shown on the dialog. If you specify no button names at all, only a single button, named “OK”, will be placed on the dialog window.
filenameSuffix
A filename extension suffix to restrict the files that the user can choose from to a certain file type. For example, you can use “txt” to only get plain text files that end in “.txt”, or “png” for Portable Network Graphics image files.
startPath
A path to a file that should be pre-selected in the dialog. On some platforms, it will just show the folder containing that file.