Commands

answer

Supported By

Syntax

answer question [with reply [or reply [or reply]]] [at point]

answer list promptText with list [at point]

answer file promptText [of type fileType [or fileType [or fileType]]] [at point]

answer (folder|directory) promptText [at point]

answer (disk|volume) promptText [at point]

Question, reply, promptText, and fileType yield strings. List yields a list. Point yields a point.

Examples

answer "Which is the way the world ends?" with "Bang" or "Whimper"
answer file "Pick a file:"

Description

The answer command displays a prompt to the user with up to three possible responses. The last response appears as the default response to the prompt. If no possible responses are specified, a single possible response will be presented with the text "OK." The script waits until one of the possible responses is chosen. The chosen response is placed in the local variable it.

The answer list command displays a prompt to the user with a list of any number of possible responses. The script waits until one of the possible responses is selected. The chosen response is placed in the local variable it and the result is set to "OK". If the prompt is dismissed without choosing a response, empty is placed in it and the result is set to "Cancel".

The answer file command displays a prompt to the user asking to select a file. The script waits until a file is selected. The path of the selected file is placed in the local variable it and the result is set to "OK". If the prompt is dismissed without selecting a file, empty is placed in it and the result is set to "Cancel".

The answer folder or answer directory command displays a prompt to the user asking to select a folder. The script waits until a folder is selected. The path of the selected folder is placed in the local variable it and the result is set to "OK". If the prompt is dismissed without selecting a folder, empty is placed in it and the result is set to "Cancel".

The answer disk or answer volume command displays a prompt to the user asking to select a disk or volume. The script waits until a volume is selected. The path of the selected volume is placed in the local variable it and the result is set to "OK". If the prompt is dismissed without selecting a volume, empty is placed in it and the result is set to "Cancel".

The exact presentation of the prompts is left to the implementation. OpenXION presents a stylized text-based prompt, or a plain text-based prompt if the -p option is given. A GUI-based system, like HyperCard, will present an appropriate dialog box. The at parameter gives a preferred location for this dialog box.

Script

on chooseColor
  answer "Which color do you prefer?" with "Red" or ¬
      "Blue" or "Yellow"
  if it is "Red" then answer "You picked red."
  else if it is "Blue" then answer "You picked blue."
  else if it is "Yellow" then answer "You picked yellow."
end chooseColor

Note

There is no way for a script to respond to a prompt by itself, so do not use answer in a script intended to run unattended.

Compatibility

HyperTalk does not support the answer list, answer directory, answer disk, or answer volume forms, or the at parameter. However, the Power Tools stack has the ShowList XFCN that inspired the answer list command and HyperTalk itself has an answer program form that OpenXION does not.

See Also

ask