Commands

ask

Supported By

Syntax

ask question [with defaultAnswer] [at point]

ask password [clear] question [with defaultAnswer] [at point]

ask file promptText [with fileName] [at point]

ask (folder|directory) promptText [with fileName] [at point]

Question, defaultAnswer, promptText, and fileName yield strings. Point yields a point.

Examples

ask "Who needs this kind of grief?" with "Not me."
ask password "Please enter your password:"
ask file "Save this file as:" with "Untitled-1"

Description

The ask command displays a prompt to the user and allows the user to type a response. The optional defaultAnswer parameter specifies a response that initially appears. The prompt appears with "OK" and "Cancel" choices as well. The script waits until a response is typed and one of the choices is selected. If the "OK" choice is selected, the typed text is placed in the local variable it and the result is set to "OK". If the "Cancel" choice is selected, empty is placed in it and the result is set to "Cancel".

The ask password command hides the response from the user as it is being typed and hashes the response using the Atkinson hash (see the hash function). The hashed response can be stored somewhere to be compared to a later response to ask password if, for example, you want the user to be able to protect data they enter.

The ask password clear command hides the response from the user as it is being typed, but does not hash the response.

The ask file command displays a prompt to the user asking for the location and name of a new file. The optional fileName parameter specifies a file name that initially appears. The script waits until a file name is entered. The file path is placed in the local variable it and the result is set to "OK". If the prompt is dismissed without entering a file name, empty is placed in it and the result is set to "Cancel".

The ask folder or ask directory command displays a prompt to the user asking for the location and name of a new folder or directory. The optional fileName parameter specifies a folder name that initially appears. The script waits until a folder name is entered. The directory path is placed in the local variable it and the result is set to "OK". If the prompt is dismissed without entering a folder name, 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.

Notes

The ask password command is not recommended for cryptographic purposes because the Atkinson hash algorithm is easily brute-forced. Instead, use the ask password clear command, then hash the cleartext password using a more secure hash algorithm.

The ask file, ask folder, and ask directory commands do not actually create the selected file or folder. The script must create the file or folder itself.

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

Compatibility

HyperTalk does not support the ask folder or ask directory forms, or the at parameter.

See Also

answer, hash