This chapter describes the terminology in AppleScript Studio’s Panel suite.
The Panel suite defines classes and events for dealing with dialogs, alerts, and panels. Most classes in this suite inherit from window
, either directly or through one of the panel classes. A panel is a special kind of window
object that can optionally be displayed as a dialog or utility window. For related information on terms used in the panel suite, see “Panels Versus Dialogs and Windows.”
The classes, commands, and events in the Panel suite are described in the following sections:
For enumerated constants, see “Enumerations.”
The Panel suite contains the following classes:
Reply record for the display
alert
command.
An alert reply is similar in concept to the dialog
alert
class defined as part of AppleScript’s Standard Additions (in the file StandardAdditions.osax
in /System/Library/ScriptingAdditions
).
See also display alert
and alert ended
.
An alert reply object has these properties. This class is not accessible in Interface Builder, so you can’t set its properties there. You can only set them in a script.
button returned | ||||
Access: | read only | |||
Class: | Unicode text | |||
the button that was clicked to end the alert; for example, “Cancel” if the user clicked the Cancel button |
This class is not accessible in Interface Builder, and you cannot connect any event handlers to it.
For an example of an alert reply, see the Examples section for the alert ended
event handler. The Display Alert application distributed with AppleScript Studio also uses an alert reply.
A type of window that provides a standard user interface for selecting color in an application.
A color panel uses a color well
to select an individual color. To use a color panel in your AppleScript Studio scripts, you can access the color panel
property that is associated with every application
object. Note that color-panel
is the class name, while color panel
specifies an object of that class.
A color panel provides a number of standard color selection modes, which you can set using the constants in Color Panel Mode. However, when you get or set a color property of an AppleScript Studio object, the color is represented as an RGB value, accessible as a three-item list that contains the values for each component of the color. For example, green can be represented as {0,65535,0}.
Figure 9-1 shows a color panel. The Opacity slider is not shown unless you set the shows alpha
property of the color panel to true
. For more information on colors and color panels, see the document Color Programming Topics for Cocoa.
In addition to the properties it inherits from the panel
class, a color
panel
object has these properties. This class is not accessible in Interface Builder, so you can’t set any of the properties there—you can only set them in a script.
alpha | ||||
Access: | read/write | |||
Class: | real | |||
the alpha value for the color; ranges from 0.0 (transparent) to 1.0 (opaque); default is 1.0 | ||||
color | ||||
Access: | read/write | |||
Class: | RGB color | |||
the color; returned as a three-item list of integers {red value, green value, blue value}; for example, {0, 0, 0} represents black, while {0, 65535, 0} represents green | ||||
color mode | ||||
Access: | read/write | |||
Class: | enumerated constant from Color Panel Mode | |||
the color mode for the panel | ||||
continuous | ||||
Access: | read/write | |||
Class: | boolean | |||
Should the color panel send color changes continuously as the user manipulates the color in the panel? default is true | ||||
shows alpha | ||||
Access: | read/write | |||
Class: | boolean | |||
Should the panel show the alpha value? default is false ; if you set this value to true , the panel displays the Opacity slider (visible in Figure 9-1)—otherwise it does not display the slider (and returns an alpha value of 1.0) |
A color-panel
object can contain only the elements it inherits from the panel
class.
This class is not accessible in Interface Builder, and you cannot connect any event handlers to it.
A script handler in an AppleScript Studio application can make the application’s color panel visible (or hide it when it is visible) by setting its visible
property. AppleScript Studio scripts implicitly target the application, so you don’t need a tell application "MyApplication"
statement to access an application property.
set visible of color panel to true |
You can use the following statement to get the currently selected color from the color panel
:
set myColor to color of color panel |
-- returns an RGB color value, as a three item list: {int, int, int} |
You can set the color of a color panel with a statement like the following:
set color of color panel to {43591, 0, 2} |
The following on launched
handler, connected to the application
object through the File’s Owner instance in the MainMenu.nib window in Interface Builder, sets the color of the application’s color panel to red and makes the panel visible when the application is launched.
on launched theObject |
set color of color panel to {65535, 0, 0} |
set visible of color panel to true |
end launched |
Starting in AppleScript Studio version 1.1, the name of the color
panel
class was changed to color-panel
. This is to make it clear which refers to the class (color-panel
) and which to the property (color panel
) of the application
object.
Prior to AppleScript Studio version 1.1, this class had limited functionality.
Reply record for the display
dialog
command.
A dialog reply is similar in concept to the dialog
reply
class defined as part of AppleScript’s Standard Additions (in the file StandardAdditions.osax
in /System/Library/ScriptingAdditions
).
See also display dialog
and dialog ended
.
A dialog reply object has these properties. This class is not accessible in Interface Builder, so you can’t set its properties there. You can only set them in a script.
This class is not accessible in Interface Builder, and you cannot connect any event handlers to it.
The following is the dialog ended
handler from the Display Dialog sample application distributed with AppleScript Studio. Display Dialog shows how to display a dialog and obtain information when it is dismissed. This handler gets called when the dialog is dismissed after it was called with the attached
to
optional parameter, so that it is shown as a sheet. The handler extracts information from the dialog
reply
object provided by theReply
parameter and displays information in the application’s window.
on dialog ended theObject with reply theReply |
-- Set the values returned in "theReply" |
set contents of text field "text returned" of window "main" to |
text returned of theReply |
set contents of text field "button returned" of window "main" to |
button returned of theReply |
set state of button "gave up" of window "main" to gave up of theReply |
end dialog ended |
A type of window that displays a list of available fonts, allowing for preview and selection of the text display font.
There is one font panel per application, accessible through the font panel
property of the application
object. Note that font-panel
is the class name, while font panel
specifies an object of that class.
Figure 9-2 shows a font panel. For AppleScript Studio limitations in font handling, see the font
class. For additional information on fonts, see the Cocoa topics Font Panel and Font Handling
In addition to the properties it inherits from the panel
class, a font
panel
object has these properties. This class is not accessible in Interface Builder, so you can’t set its properties there. You can only set them in a script.
enabled | ||||
Access: | read/write | |||
Class: | boolean | |||
Is the panel enabled? | ||||
font | ||||
Access: | read/write | |||
Class: | font | |||
the current font |
A font-panel
object can contain only the elements it inherits from panel
.
This class is not accessible in Interface Builder, and you cannot connect any event handlers to it.
A script handler in an AppleScript Studio application can refer to the font panel
property of the application
object without having to specify the application, as in the following statement, which shows the font panel:
set visible of font panel to true |
Starting in AppleScript Studio version 1.1, the name of the font
panel
class was changed to font-panel
. This is to make it clear which refers to the class (font-panel
) and which to the property (font panel
) of the application
object.
Prior to AppleScript Studio version 1.1, this class had limited functionality.
Provides a standard dialog applications can use to query a user for the name of a file to open.
An open panel can be run as application modal or document modal (as a sheet attached to a window). Note that open-panel
is the class name, while open panel
specifies an object of that class.
To use an open panel in an AppleScript Studio application, you use the display
command to display the open panel
property that is associated with every application
object. If you display the panel as a sheet (attached to a window), you will also need to connect a panel ended
event handler. When the user closes the panel, you can get information, such as a list of paths to the files the user has selected, by accessing properties of the open-panel
object.
An open panel
object only understands and returns only POSIX style (slash-delimited) paths. It does not understand file
or alias
types. You can, however, use POSIX file
and POSIX
path
from AppleScript's Standard Additions scripting additions to convert between path types. They are defined in the file StandardAdditions.osax
in /System/Library/ScriptingAdditions
.
For more information, see save-panel
, as well as the Cocoa topics Application File Management and Window Programming Guide for Cocoa.
Figure 9-3 shows an open panel.
In addition to the properties it inherits from the save-panel
class, an open
panel
object has these properties (see the Version Notes section for this class for the AppleScript Studio version in which a particular property was added). This class is not accessible in Interface Builder, so you can’t set its properties there. The Open Panel sample application, available at <Xcode>/Examples/AppleScript Studio
starting with AppleScript Studio version 1.1, demonstrates how to set many open panel properties in a script.
An open-panel
object can contain only the elements it inherits from panel
.
Your script can send the following commands to an open
panel
object:
display | ||||
display panel |
This class is not accessible in Interface Builder, and you cannot connect any event handlers to it.
A script handler in an AppleScript Studio application can refer to the open panel
property of the application
object without having to specify the application, as in the following statement, which obtains the list of full POSIX style (slash-delimited) paths for the files chosen in the open panel:
set fileList to path names of open panel |
An application could use the following clicked handler to prompt a user to choose a folder. This handler first sets properties of the open panel
property of the application object to specify a folder (or directory) to search. Note that you don’t need to implicitly specify the open panel as belonging to the application object.
on clicked theObject |
set can choose directories of open panel to true |
set can choose files of open panel to false |
display open panel attached to window "main" |
end clicked |
Because the handler displays the panel as a sheet, the panel is document modal, which means that application execution continues after the panel is displayed. So to get the user’s choice from the panel, the application needs to use Interface Builder to connect a panel ended
handler to the window
to which the panel is attached. The panel ended
handler is called when the panel is dismissed. In the example shown here, the handler checks the result and if it is 1 (a folder was chosen; 0 indicates the panel was cancelled), extracts the folder from the returned list. As mentioned above, the folder path is a POSIX style path.
on panel ended theObject with result withResult |
if withResult is 1 then |
set theFolder to item 1 of (path names of open panel as list) |
-- do something with the supplied folder path |
end if |
end panel ended |
If a script does not attach the panel to a window, the panel is displayed as application modal, and execution halts until the panel is dismissed. In that case, a panel ended
event handler is not needed.
The Open Panel sample application, available at <Xcode>/Examples/AppleScript Studio
starting with AppleScript Studio version 1.1), demonstrates how to use an open panel, both as a separate panel and as a sheet. See the “Terminology” for information on how to read and write files.
The path names
property was added in AppleScript Studio version 1.1.
Starting in AppleScript Studio version 1.1, the name of the open
panel
class was changed to open-panel
. This is to make it clear which refers to the class (open-panel
) and which to the property (open panel
) of the application
object.
Prior to AppleScript Studio version 1.1, this class had limited functionality.
The Open Panel sample application was first distributed with AppleScript Studio version 1.1.
A type of window that typically serves an auxiliary function in an application.
A panel can optionally be displayed as a utility window
, which can float above other windows. You create a panel in Interface Builder by dragging a panel object from the Cocoa Windows pane of the Palette window. The color-panel
and font-panel
classes are based on Cocoa classes that descend from NSPanel.
For more information, see the display
command, as well as the document Window Programming Guide for Cocoa.
In addition to the properties it inherits from the window
class, a panel object has these properties:
floating | ||||
Access: | read/write | |||
Class: | boolean | |||
Is the panel a floating panel? |
An panel
object can contain only the elements it inherits from window
.
Your script can send the following commands to a panel object:
close panel | ||||
display | ||||
display panel |
A panel object supports handlers that can respond to the following events:
Keykeyboard down | ||||
keyboard up |
mouse down | ||||
mouse dragged | ||||
mouse entered | ||||
mouse exited | ||||
mouse up | ||||
right mouse down | ||||
right mouse dragged | ||||
right mouse up | ||||
scroll wheel |
awake from nib |
alert ended | ||||
dialog ended | ||||
panel ended |
The following is a partial listing of the clicked
handler for the main window in the Display Panel sample application distributed with AppleScript Studio. This handler is in the file Window.applescript
. The Display Panel application shows how to display a panel and obtain information when it is dismissed. Because this handler uses the attached
to
parameter to specify that the panel should be displayed attached to the window “main”, the application supplies a panel ended
handler that is called when the panel is dismissed. No panel
ended
handler is needed if the panel is not attached, because then it is displayed in document-modal fashion and control continues in the statement after the panel is displayed.
on clicked theObject |
-- Some statements not shown |
-- Make sure panel has been loaded from nib into global property |
if not (exists panelWIndow) then |
load nib "SettingsPanel" |
set panelWIndow to window "settings" |
end if |
-- Statements for setting state of panel items not shown |
-- Now display the panel |
display panelWIndow attached to window "main" |
-- Other statements not shown |
end clicked |
The Display Panel sample application uses the following statement to display an application-modal panel. The call to display
returns the number of the button used to dismiss the panel, and the result is used here in an if
statement test. A return value of 0 indicates the panel was cancelled; 1 indicates it was accepted.
if (display panelWIndow) is 1 then |
Note: The Display Panel application uses the display
command, which is the preferred way to display a panel, rather than the display panel
command.
Allows users to specify the directory and name under which a file is saved.
The save-panel
class supports browsing of the file system and it accommodates custom accessory views. To use a save panel in your AppleScript Studio scripts, you can access the save panel
property that is associated with every application
object. Note that save-panel
is the class name, while save panel
specifies an object of that class.
To use a save panel in an AppleScript Studio application, you use the display
command to display the save panel
property that is associated with every application
object. If you display the panel as a sheet (attached to a window), you will also need to connect a panel ended
event handler. When the user closes the panel, you can get information, such as path name the user has chosen for saving a file, by accessing properties of the save-panel
object.
A save panel
object only understands and works with POSIX style (slash-delimited) paths. It does not understand file
or alias
types. You can however use AppleScript's POSIX file
and POSIX
path
, defined as part of AppleScript’s Standard Additions (in the file StandardAdditions.osax
in /System/Library/ScriptingAdditions
), to convert between path types.
Figure 9-4 shows a save panel. For more information on panels, see open-panel
, as well as the document Window Programming Guide for Cocoa.
In addition to the properties it inherits from the panel
class, a save
panel
object has these properties. This class is not accessible in Interface Builder, so you can’t set its properties there. The Save Panel sample application, available at <Xcode>/Examples/AppleScript Studio
starting with AppleScript Studio version 1.1, demonstrates how to set many save panel properties in a script.
A save-panel
object can contain only the elements it inherits from panel
.
Your script can send the following commands to a save
panel
object:
display | ||||
display panel |
This class is not accessible in Interface Builder, and you cannot connect any event handlers to it.
A script handler in an AppleScript Studio application can refer to the save panel
property of the application
object without having to specify the application, as in the following statement, which displays the save panel (attached to the window with AppleScript name “main”):
display save panel attached to window "main" |
Because the statement displays the panel as a sheet, the panel will be document modal, which means that application execution continues after the panel is displayed. So to get the user’s choice from the panel, the application needs to use Interface Builder to connect a panel ended
handler to the window
to which the panel is attached. The panel ended
handler is called when the panel is dismissed.
If a script does not attach the panel to a window, the panel is displayed as application modal, and execution halts until the panel is dismissed. In that case, a panel ended
event handler is not needed.
For a summary of how to use the save panel, see the Examples section of the display
command and the Save Panel application distributed with AppleScript Studio. For an example that shows how to use an open panel, see the Examples section of the open-panel
class. See the “Terminology” for information on how to read and write files.
Starting in AppleScript Studio version 1.1, the name of the save
panel
class was changed to save-panel
. This is to make it clear which refers to the class (save-panel
) and which to the property (save panel
) of the application
object.
Prior to AppleScript Studio version 1.1, this class had limited functionality.
Prior to AppleScript Studio version 1.1, the name of the path
name
property was file name
.
The Save Panel sample application was first distributed with AppleScript Studio version 1.1.
Objects based on classes in the Panel suite support the following commands. (A command is a word or phrase a script can use to request an action.) To determine which classes support which commands, see the individual class descriptions.
Closes the specified panel, optionally supplying a return value.
A panel is a special kind of window
object that can optionally be displayed as a utility window. The panel
and color-panel
classes are examples of panels.
close panel |
reference | required | |
with result |
anything | optional |
a reference to the panel to close
with result
anythingthe result of the panel; must be either a number or a string that can be coerced to a number; for example, an integer indicating the button pressed
The following is the clicked
handler for the buttons in the panel window in the Display Panel sample application distributed with AppleScript Studio. This handler is in the file Settings.applescript
. The Display Panel application shows how to display a panel and obtain information when it is dismissed.
If the panel is displayed as a sheet (document modal), application execution continues after the panel is displayed. To get the user’s choice from the panel, the application connects a panel ended
handler to the window
to which the panel is attached (as described in the Examples section for the panel
class). The panel
ended
handler is called when the panel is dismissed. The value returned by the close
panel
command is passed to panel ended
handler, which does nothing unless the value is 1, indicating the user clicked the Change button (not the Cancel button).
If the panel was displayed as a separate window (application modal), execution halts until the panel is dismissed. In that case, a panel ended
event handler is not needed. The value returned by the close
panel
command is returned directly to the calling script, which again does nothing unless the value is 1, indicating the user clicked the Change button (not the Cancel button).
on clicked theObject |
if name of theObject is "cancel" then |
close panel (window of theObject) |
else if name of theObject is "change" then |
close panel (window of theObject) with result 1 |
end if |
end clicked |
Presents a panel in an application-modal fashion, or in document-modal fashion (as a sheet) when the optional attached
to
parameter is used.
You should use display rather than display panel
to display open-panel
, save-panel
, or any other panels. For examples that show the correct terminology, see the Examples section below.
The display
command allows your application to display the open and save panels that have been added as properties of the application
object in AppleScript Studio version 1.1.
display |
reference | required | |
afterwards calling |
anything | optional | |
attached to |
window | optional | |
for file types |
list | optional | |
in directory |
Unicode text | optional | |
with file name |
Unicode text | optional |
a reference to the window to display (in which case, you use a statement like display panelWindow
; for a save or open panel, use display save
panel
or display open panel
)
afterwards calling
anythingnot supported (through AppleScript Studio version 1.4); a reference to a script to run when the displayed window is dismissed
attached to
windowthe window to attach the displayed window to; attaching the window makes it document modal (attached as a sheet to the specified window)
for file types
lista list of file extension that are allowed (for open/save panels), such as “rtf” or “txt”; do not include the period that begins the extension
in directory
Unicode textthe starting directory (for open/save panels)
with file name
Unicode textthe default file name (for open/save panels)
A value indicating which button was used to dismiss the panel. For AppleScript Studio’s Save and Open panels, 0 represents the Cancel button and 1 represents the Save or Open button. If you use the display command with your own panel, you call the close panel
command, passing an integer value that is in turn passed on to your panel ended
handler, and represents how your panel was dismissed. In that case, return values are arbitrary, and it’s up to your application to assign them and interpret them.
You typically use steps like the following, based on the Save Panel sample application distributed with AppleScript Studio, to display and respond to a save or open panel (in this case, a save panel):
Set up your application in Interface Builder.
You may want to display the panel when a user clicks a button in a window. To do so, use a clicked
handler, as in Save Panel.
Or you may want to display the panel when a user chooses the Save item in the File menu. In that case, use a choose menu item
handler.
If you will show the panel as a sheet, connect a panel ended
handler to the window to which you will attach the panel.
To display the panel as a sheet (document modal), use the attached
to
parameter and don’t expect to get an immediate response. The panel ended
handler will be called when the user dismisses the panel, and you can get the information you need about the panel there, as described in the Examples section for panel ended
.
Here’s how the Save Panel application displays a panel as a sheet:
display save panel in directory theDirectory with file name theFileName attached to window of theObject |
Note that when you display AppleScript Studio’s built-in save panel, shown in Figure 9-4, you’re actually using the save panel
property of the application
object.
If you display the panel in the standard (non-sheet) way, the result is application modal (nothing else can happen until the user responds). Control returns to the script statement following the display save panel
statement. Here is how the Save Panel application does it:
set theResult to display save panel in directory theDirectory with file name theFileName |
The result is an integer, where 0 represents the Cancel button and 1 represents the Save button.
You can also use display to display a panel you have constructed in Interface builder (instead of the standard Save panel provided by AppleScript Studio). In that case, you will need to call the close panel
command when your panel is dismissed. For details on how to do so, see the Display Panel application distributed with AppleScript Studio.
Given a window “main” and a panel window “preferences” in a nib named “preferences.nib”, the following script displays the panel window attached to the window:
load nib "preferences" |
set preferencesPanel to window "preferences" |
display preferencesPanel attached to window "main" |
When you display a window in application-modal fashion, your script waits for the user to dismiss the window. If you display the window in document-modal fashion by specifying the optional attached
to
parameter, script execution continues. To perform any actions when the user dismisses the window, you have to supply a panel ended
handler. You can see an example of this handler in the Display Panel sample application distributed with AppleScript Studio.
The afterwards calling
parameter to this command is not supported, through AppleScript Studio version 1.4.
Starting in AppleScript Studio version 1.2, the display
command is recommended as a replacement for the display
panel
command.
The display
command was added in AppleScript Studio version 1.1. Prior to version 1.1, you can use the display panel
command. (A different display
command was available in the Application suite in AppleScript Studio version 1.0.)
The Save Panel application was first distributed with AppleScript Studio version 1.1.
Displays the specified alert.
The many optional parameters allow you to control how the alert is displayed. You typically display an alert to provide information that the user should reply to immediately. However, you can display an alert as a sheet (attached to a window), allowing a user to continue to work with other windows before responding to the alert.
Figure 9-5 shows an alert displayed as a sheet by the Display Alert sample application distributed with AppleScript Studio.
text to display in the alert; can be an empty string
afterwards calling
anythingnot supported (through AppleScript Studio version 1.4); a reference to a script to run when the alert is finished
alternate button
Unicode textthe title of the alternate button
as
enumerated constant from Alert Typethe type of alert
attached to
windowthe window to attach the alert to
default button
Unicode textthe title of the default button
message
Unicode textthe message for the alert
other button
Unicode textthe title of the other button
An alert reply
that contains information on the dismissed alert. When the alert is displayed as a sheet (attached to a window), there is no immediate result, and you must install an alert ended
handler to respond to the alert being dismissed.
The following statement shows the syntax for displaying an alert as a sheet (which results in a document-modal alert). It is taken from the clicked
handler of the Display Alert application distributed with AppleScript Studio. Most of the parameters are variables that are set from text fields in the application’s main window (not shown).
Note: There are no line breaks in the following examples—each includes just one AppleScript statement.
display alert dialogText as dialogType message dialogMessage default button defaultButtonTitle alternate button alternateButtonTitle other button otherButtonTitle attached to window "main" |
When you display an alert attached to a window, you must install an alert ended
handler for the window. The handler is called when the alert is dismissed. For an example of an alert ended
handler, see the Examples section of the alert ended
handler.
The following statement shows the syntax for displaying an alert that not attached to a window (and is therefore application modal). Again, most of the parameters are variables that are set from text fields in the application’s main window (not shown). In this case, though, execution stops until the alert is dismissed, and display alert
returns an alert reply
, from which you can get information about how the alert was dismissed (as shown the Examples section of the alert ended
handler).
set theReply to display alert dialogText as dialogType message dialogMessage default button defaultButtonTitle alternate button alternateButtonTitle other button otherButtonTitle |
The afterwards calling
parameter to this command is not supported, through AppleScript Studio version 1.4.
Displays the specified dialog.
AppleScript Studio overrides the display
dialog
scripting addition command (provided in the file /System/Library/ScriptingAdditions/StandardAdditions.osax
) to implement its own version.
This command has many optional parameters to allow you to control how the dialog is displayed. For example, you can present the window in an application-modal fashion, or in document-modal fashion (as a sheet). Displaying a dialog as a sheet allows a user to continue to work with other windows before responding.
Important: Read the Discussion section below for important information about working with a dialog displayed as a sheet.
Figure 9-6 shows a dialog displayed as a sheet by the Display Dialog sample application distributed with AppleScript Studio. Display Dialog shows how to display a dialog and obtain information when it is dismissed.
a reference to the dialog window to display
attached to
windowthe window to attach the dialog to; supplying this parameter causes the dialog to be displayed in document-modal fashion, attached to the specified window
buttons
lista list of up to three button names
default answer
Unicode textthe default editable text
default button
anythingthe name or number of the default button
giving up after
integernumber of seconds to wait before automatically dismissing the dialog
with icon
anythinga string or integer that specifies the icon to display; for a string, the string must specify a TIFF file (without the .tiff
extension) in the project that contains an icon image; for an integer, you can use the values 0, 1, or 2 to get system-supplied icons, or you can pass one of the enumerated values from Alert Type
A dialog reply
that contains information on the dismissed dialog. When the dialog is displayed as a sheet (attached to a window), there is no immediate result, and you must install a dialog ended
handler to respond to the dialog being dismissed.
The following example displays a dialog with text and three buttons. It specifies a timeout value (giving
up after 10
) and a default button (default
button "Goodbye"
). The example then displays a second dialog to show which button was clicked:
on clicked theObject |
set theReply to display dialog "Please click a button." buttons {"Hello", "Goodbye", "OK"} default button "Goodbye" giving up after 10 |
display dialog button returned of theReply |
end clicked |
Note: In the previous on
clicked
handler, there are no line breaks in the statement beginning with set theReply
to
and ending with giving up
after 10
.
In this example, control does not return to the second display
dialog
statement until either the user clicks a button (or presses the Return key for the default), or waits more than 10 seconds, causing a timeout.
You can display an application-defined icon by specifying the TIFF file for the icon. For example, if the file is named myIcon.tiff
and you’ve dragged it into the Xcode project for the application, you could add with icon myIcon
after giving
up after 10
in the clicked
handler above.
See the Discussion section for information about displaying a dialog as a sheet (attached to a window). For a more complete example, see the Display Dialog sample application distributed with AppleScript Studio, as well as the Examples section of the dialog reply
class.
When you display a dialog independently, script execution stops until the dialog is dismissed, at which point it continues with the statement following the display dialog
statement.
When you display a dialog as a sheet (attached to a window), script execution continues, and the following statement is executed immediately. This can lead to some confusion. To get control when the user dismisses the dialog, you install a dialog
ended
handler, as demonstrated in the Display Dialog sample application distributed with AppleScript Studio.
When you display a dialog independently, the display
dialog
command generates a “user canceled” error when the cancel button is pressed. Your script should use a try on error
block (also demonstrated in the Display Dialog application) to deal with the error.
When you display a dialog attached to a window, your dialog
ended
handler can treat cancel like any other button.
Starting with AppleScript Studio version 1.1, you can pass a number to the display dialog
command without having to coerce it to a string, as shown in the following statement (where amount
and rate
are previously defined numeric variables):
display dialog amount * rate |
For another simple example, the following statement displays a minimal dialog (with Cancel and OK buttons) that contains displays the string “10” and dismisses itself after 3 seconds if the user doesn’t respond:
display dialog 10 giving up after 3 |
Displays the specified panel window.
Not recommended, starting in AppleScript Studio version 1.2. Use display
instead. The optional parameters allow you to control how the panel window is displayed.
display panel |
reference | required | |
afterwards calling |
anything | optional | |
attached to |
window | optional | |
for file types |
list | optional | |
in directory |
Unicode text | optional | |
with file name |
Unicode text | optional |
a reference to the window to display
afterwards calling
anythingthe script to run when the display is finished
attached to
windowthe window to attach the panel window to
for file types
lista list of file extension that are allowed (for open/save panels)
in directory
Unicode textthe starting directory (for open/save panels)
with file name
Unicode textthe default file name (for open/save panels)
an integer value representing the button that dismissed the panel; a return value of 0 indicates the panel was cancelled; 1 indicates it was accepted
For examples that show how to load and display a panel, see the Examples sections of the panel ended
and load nib
event handlers.
Starting in AppleScript Studio version 1.2, this command is not recommended—use display
instead.
Not recommended, starting with AppleScript Studio version 1.1. Loads the specified panel from the specified nib file.
load panel |
reference | required | |
from nib |
Unicode text | optional |
a reference to the panel window to load
from nib
Unicode textthe name of the nib to get the panel window from
To use this command, you insert a panel window in your nib file and supply a window title on the Attributes pane of the Info window (not an AppleScript name, which you specify on the AppleScript pane). You then load the panel in a script by specifying the window title. For example, given a window with title “myWindow” in a nib file “myNib”, you could load an instance of the window for use as a panel with the following statement:
load panel "myWindow" from nib "myNib" |
Starting in AppleScript Studio version 1.2, this command is not recommended—use load nib
instead.
Objects based on classes in the Panel suite support handlers for the following events (an event is an action, typically generated through interaction with an application’s user interface, that causes a handler for the appropriate object to be executed). To determine which classes support which events, see the individual class descriptions.
Called after an alert ends if the alert panel was displayed attached to a window.
When you display an alert in application-modal fashion, your script waits for the user to dismiss the alert. If you display the alert in document-modal fashion by specifying the optional attached
to
parameter, script execution continues. To perform any actions when the user dismisses the alert, you have to supply an alert ended
handler.
alert ended |
reference | required | |
with reply |
alert reply | optional |
a reference to the window
to which the panel was attached
with reply
alert replythe reply returned from the alert
When you connect an alert ended
handler to a window
object in Interface Builder, AppleScript Studio supplies an empty handler template. The following handler is from the Display Alert sample application distributed with AppleScript Studio. The handler obtains the name of the button returned from the with reply
parameter and uses it to set the contents of a text field (also named “button returned”).
on alert ended theObject with reply theReply |
set contents of text field "button returned" of window "main" |
to button returned of the reply |
end alert ended |
Called after a dialog ends if the dialog was displayed attached to a window.
When you display a dialog in application-modal fashion, your script waits for the user to dismiss the dialog. If you display the dialog in document-modal fashion by specifying the optional attached
to
parameter, script execution continues. To perform any actions when the user dismisses the alert, you have to supply a dialog ended
handler.
dialog ended |
reference | required | |
with reply |
dialog reply | optional |
a reference to the panel for which the handler is called
with reply
dialog replythe reply returned from the dialog
For an example of a dialog ended handler, see the Examples section of the dialog reply
command.
Called after a panel ends if the panel was displayed attached to a window.
When you display a panel in application-modal fashion, your script waits for the user to dismiss the panel. If you display the panel in document-modal fashion by specifying the optional attached
to
parameter, script execution continues. To perform any actions when the user dismisses the panel, you have to supply a panel ended
handler.
The panel ended
event handler is called in the script that is connected to the window that the open-panel
or save-panel
is connected to. For example, if your window event handlers are connected to a script named Window.applescript
and your script displays a panel with a statement like display
open panel attached to window "main"
, then the panel ended
event handler should also be connected to Window.applescript
. The handler is called when the panel is dismissed.
panel ended |
reference | required | |
with result |
anything | optional |
a reference to the panel for which the handler is called
with result
anythingthe result returned from the panel
The following panel ended
handler is from the Save Panel sample application, available at <Xcode>/Examples/AppleScript Studio
(starting with AppleScript Studio version 1.1). You connect the handler to a window in Interface Builder. Then your application calls the display panel
command, using the optional attached
to window
parameter to attach the panel to the window with the panel ended
handler. The handler is called when the panel is dismissed.
on panel ended theObject with result withResult |
if withResult is 1 then |
set contents of text field "path name" of window "main" |
to path name of save panel |
else |
set contents of text field "path name" of window "main" to "" |
end if |
end panel ended |
The Save Panel application uses the following statement to display a panel attached to a window that uses the panel
ended
handler shown above. The in
directory
and with file
name
parameters are optional.
display save panel in directory theDirectory |
with file name theFileName attached to window of theObject |
For more information, see the Examples section of the display
command.
The Save Panel application was first distributed with AppleScript Studio version 1.1.
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-10-31)