These commands let you pause your script to get input from the user. To create complex custom user interfaces, see
Creating interfaces.
Asking a question with confirmDialog
The
confirmDialog command creates a modal window with a message to the user and any number of buttons.
The window disappears when the user presses any button or clicks the window’s close button.
- Use the message flag to set the text string that appears above the buttons.
- Add a
button flag with the title string of each button.
- Use the
defaultButton flag to specify which button corresponds to the Enter key.
- Use the
cancelButton flag to specify which button corresponds to the Esc key.
- If the user clicks a button, the name of the button is returned.
- If the user clicks the window’s close button, the string specified by the
dismissString flag is returned.
confirmDialog -title "Confirm" -message "Are you sure?"
-button "OK" -button "Cancel" -defaultButton "OK"
-cancelButton "Cancel" -dismissString "Cancel";
Letting the user choose a file with fileDialog
The
fileDialog command shows a file open dialog window.
fileDialog -directoryMask "*.txt"
Getting a string with promptDialog
The
promptDialog command creates a window with a message to the user, a text box, and any number of buttons.
- Use the
title flag to set the window title. Use the
message flag to set the string that appears above the text box and buttons.
- Use the
text flag to set the initial contents of the text box. Use the
scrollableField flag to change the text box to a multi-line scroll field.
- Add a
button flag with the title string of each button.
- Use the
defaultButton flag to specify which button corresponds to the Enter key.
- Use the
cancelButton flag to specify which button corresponds to the Esc key.
- If the user clicks a button, the name of the button is returned.
- If the user clicks the window’s close button, the string specified by the
dismissString flag is returned.
- After the command returns, use the command again with
query flag and the
text flag to get the text the user entered.
// Show the dialog box:
string $text;
string $result = `promptDialog
-title "Rename Object"
-message "Enter Name:"
-button "OK" -button "Cancel"
-defaultButton "OK" -cancelButton "Cancel"
-dismissString "Cancel"`;
// Use the command again in query mode to
// get the text:
if ($result == "OK") {
$text = `promptDialog -query -text`;
}