ask
Syntax
ask <prompt> [with <defaultAnswer>]
ask {file|folder} <prompt> [with <startPath>]
ask "What's your favorite food?" with "Lentil Soup"
ask file "Save this project:" with "/Users/helen/My Comic Database.xstk"
ask folder "Create a new folder:" with "/Applications/Pixelmator"
Explanation
The ask
command displays various modal dialogs that halt your script until
the user has finished with them, which contain a text field for the user to
type in text.
The simple form of ask
displays a text prompt in a dialog window, with a text
field to enter some text in and an “OK” and a “Cancel” button. When the user
clicks one of the buttons, the dialog window closes, and the text the user entered
will be stored in 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 ask file
form of the command shows a file picker dialog for saving
a file on the user’s hard disk (or mounted servers, or anything else that would
usually be listed in a file picker). The user can select a folder to put the file
in and enter a name to give the file in an edit field. The full search path for the
file will be written to the variable it
once the dialog closes. the result
will
be set to the name of the button that was clicked to close the dialog (either OK
or Cancel
).
The ask folder
form of the command shows a folder picker dialog for creating
a folder on the user’s hard disk (or mounted servers, or anything else that would
usually be listed in a file picker). The user can select a parent folder to put the
new folder in and enter a name to give the folder in an edit field. The full search
path for the folder will be written to the variable it
once the dialog closes.
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.
defaultAnswer
The text to show in the edit field when the dialog opens.
startPath
A path to a file/folder whose parent folder should be pre-selected in the dialog, and whose name will be used to pre-fill the filename edit field. You can also specify just a file name, to just pre-fill the edit field with a default name.