Tools: MPW
Advanced Search
Apple Developer Connection
Member Login Log In | Not a Member? Support

MPW Command Reference


Confirm

Built-in

SYNTAX

Confirm [message…] [-t]

DESCRIPTION

The Confirm command displays a confirmation dialog box with OK and Cancel buttons and the prompt message and returns the result in the {Status} variable. See the Status section for possible values of the {Status} variable.

INPUT

Standard input, unless you specify the message parameter.

OUTPUT

None

STATUS

Confirm can return the following status codes:

0

OK (in a two-way dialog box) or Yes (in a three-way dialog box) selected

1

syntax error

4

Cancel (in a two-way dialog box) or No (in a three-way dialog box) selected

5

Cancel selected in a three-way dialog box

Note
In a two-way dialog box, Cancel means the same thing as No; OK means Yes. •

Note
Since Confirm returns a nonzero status code to indicate that No or Cancel was selected, you must set the MPW Shell variable {Exit} to zero before using the command in a script. This step is necessary because the MPW Shell aborts script processing when a nonzero {Status} code is returned and {Exit} is nonzero. •

PARAMETERS

message

Specifies the message appearing in the confirmation dialog box. Be sure to place the message within quotation marks, which are stripped before the message appears in the dialog box.

OPTIONS

-t

Displays a three-way confirmation dialog box with Yes, No, and Cancel buttons. In this case, a status of 4 means No and 5 means Cancel.

EXAMPLES

The command line

Confirm "Is this the correct file?"

displays the dialog box shown below.

Clicking OK generates a status code of 0, while clicking Cancel generates a status code of 4. Remember that the status code is stored in the {Status} variable and can easily be retrieved by using the command

Echo {Status}

When you use the Finder to copy one or more files to a folder or disk that already contains files of the same names, the Finder displays a dialog box asking if you want to replace the files. The same task can be accomplished with the following script:

Set Exit 0
Confirm "Replace files with the same name?"
If {Status} == 0
  Duplicate -y Source:≈ Destination:
End
Set Exit 1

which displays the dialog box shown below.

If you click the OK button, the MPW Shell executes the Duplicate command.

The following script makes use of a three-way confirmation dialog box to print selected 'TEXT' files in the current directory:

Set Exit 0
Set list ""
For file In `files -t TEXT`
    Confirm -t "Print file {file}?"
    Set SaveStatus "{Status}"
    Continue If "{SaveStatus}" == 4    # No
    Break If "{SaveStatus}" == 5       # Cancel
    Set list "{list} '{file}'          # Yes
End 
If "{list}" != ""
    Print {PrintOptions} {list} 
End
Set Exit 1

For each file, the script displays a dialog box with Yes, No, and Cancel buttons. If you click Yes, the file is placed in a list of files to be printed. If you click No, the Continue command causes this file to be skipped, but processing continues with the next file in the list. If you click Cancel, the Break command causes the For loop to be terminated, ending the question-and-answer session. The filenames are saved in the variable {list} and printed after the loop.

SEE ALSO

Alert

Request

 
 


Last Updated July 2000