This chapter describes the terminology in AppleScript Studio’s Control View suite, which defines classes for implementing or working with controls. Controls are graphic objects that cause instant actions or visible results when a user manipulates them with the mouse.
Most classes in this suite inherit from the view class, either directly or through the control class.
The classes, commands, and events in the Control View suite are described in the following sections:
For enumerated constants, see “Enumerations.”
The Control View suite contains the following classes:
Defines an active area inside a control or one of its subclasses.
As the active area of a control, an action
cell does three things: it usually performs display of text or an icon; it provides the control with a target and an action; and it handles mouse (cursor) tracking by properly highlighting its area and sending action messages to its target based on cursor movement.
This class is not accessible in Interface Builder, and you cannot connect any event handlers to it.
See the examples for cell.
Control subclass that intercepts mouse-down events and initiates a handler call when it is clicked or pressed.
A button contains a single button cell. Figure 4-1 shows a simple button.
You will find an assortment of buttons on the Cocoa-Controls pane of Interface Builder’s Palette window. You can set many attributes for buttons in Interface Builder’s Info window. You can also change button types in your scripts, using the constants defined in Button Type.
In addition to the properties it inherits from the control class, a button object has these properties:
allows mixed state | ||||
| Access: | read/write | |||
| Class: | boolean | |||
Does the button allow a mixed state? (see also the state property); some buttons may reflect only two states, such as on or off; a mixed state reflects more than two states; suppose, for a simple-minded example, that a checkbox makes selected text bold; if all the selected text is bold, the checkbox is on; if none of the selected text is bold, it's off; if the selected text has a combination of bold and plain text, the state is mixed | ||||
alternate image | ||||
| Access: | read/write | |||
| Class: | image | |||
| the image for the button when it is in its alternate state; see the Discussion section | ||||
alternate title | ||||
| Access: | read/write | |||
| Class: | Unicode text | |||
| the title of the button when it is in its alternate state; see the Discussion section | ||||
bezel style | ||||
| Access: | read/write | |||
| Class: | enumerated constant from Bezel Style | |||
| the bezel style of the button | ||||
bordered | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Does the button have a border? | ||||
button type | ||||
| Access: | read/write | |||
| Class: | enumerated constant from Button Type | |||
| the type of button | ||||
image | ||||
| Access: | read/write | |||
| Class: | image | |||
| the image of the button; see the Discussion section | ||||
image position | ||||
| Access: | read/write | |||
| Class: | enumerated constant from Cell Image Position | |||
the position of the image in the button, as a two-item list of numbers {left, bottom}; every window and view has its own coordinate system, with the origin in the lower left corner; see the bounds property of the window class for more information on the coordinate system; for changes introduced in AppleScript Studio version 1.4, see the main discussion for the application class, as well as the coordinate system property of that class | ||||
key equivalent | ||||
| Access: | read/write | |||
| Class: | Unicode text | |||
| the key equivalent to clicking on the button; for example, the key equivalent might be the letter “U” or the combination Command-U; you can set this property on the attributes pane in the Info window in Interface Builder, where, for example, you can set a button to be the default button by choosing “Return” on the pop-up menu for the “Equiv.” field; the default button automatically pulses and takes on the default color | ||||
key equivalent modifier | ||||
| Access: | read/write | |||
| Class: | number | |||
| the modifier key for the key equivalent; you can set this property to either or both the Command and Option keys in the Info window in Interface Builder; however, the value returned by this property is a number; default is 0 (or no modifier) | ||||
roll over | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Does the button act like a roll over? | ||||
sound | ||||
| Access: | read/write | |||
| Class: | sound | |||
| the sound of the button when it is clicked | ||||
state | ||||
| Access: | read/write | |||
| Class: | enumerated constant from Cell State Value | |||
the state of the button; (see also the allows
mixed state property) | ||||
title | ||||
| Access: | read/write | |||
| Class: | Unicode text | |||
| the title of the button; see the Discussion section | ||||
transparent | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Is the button transparent? | ||||
A button object can contain only the elements it inherits from control.
Your script can send the following command to a button object:
highlight |
A button object supports handlers that can respond to the following events:
Action
clicked |
conclude drop | ||||
drag | ||||
drag entered | ||||
drag exited | ||||
drag updated | ||||
drop | ||||
prepare drop |
keyboard 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 |
bounds changed |
AppleScript Studio provides access to many types of button objects and the sample applications distributed with AppleScript Studio include many examples of working with buttons. The following script statements demonstrate some of the basic terminology for using buttons.
In the most common case, you use a button to trigger an action in a clicked handler. The following clicked handler, from the Currency Converter sample application, just performs the currency conversion, based on the values the user has supplied, and displays the result. The clicked handler’s theObject parameter refers to the button. In this case, the handler uses the window of the button to get at other objects.
on clicked theObject |
tell window of theObject |
try |
set theRate to contents of text field "rate" |
set theAmount to contents of text field "amount" as number |
set contents of text field "total" to theRate * theAmount |
on error |
set contents of text field "total" to 0 |
end try |
end tell |
end clicked |
The following statement disables a button with AppleScript name “someButton”.
set enabled of button "someButton" to false |
You implement radio buttons with a matrix object. See that class for examples.
The following statements, from the clicked handler of the Unit Converter sample application, show how to determine if a particular button was the target for a view that has more than one button that may need to respond. In this case, the button of interest (the Convert button) is part of a box object.
on clicked theObject |
tell window "Main" |
if theObject is equal to button "Convert" of box 1 then |
my convert() |
else if ... |
... |
end tell |
end clicked |
Buttons provide a simple mechanism for switching the button title or image as a user toggles the button state. For example, to create a button in Interface Builder that toggles its text between “Start” and “Stop”, you use these steps:
Drag a button object from the Cocoa-Controls pane of the Palette window to the target window. You can use any button that shows “NSButton” when you rest the cursor over it in the Palette window.
With the button selected in the target window, open the Info window by choosing Show Info from the Tools menu or by typing Command-Shift-I.
If the Behavior pop-up on the attributes pane of the Info window isn’t enabled, choose a button type in the Type pop-up that causes the Behavior pop-up to be enabled. For example, you might set the button type to Rounded Bevel Button, Square Button, or Round Button.
Set the Behavior pop-up to Toggle.
Type “Start” in the Title field and “Stop” in the Alt. Title field.
To test the button, choose Test Interface from the File menu (or type Command-R). You should be able to click the button and toggle its title between “Start” and “Stop”.
The Attributes pane provides other button settings, including fields for setting an icon and an alternate icon for buttons that show an icon. Note that you can display any image in the button, not just an icon.
Subclass of cell that implements the user interface for push buttons, switches, and radio buttons.
You don’t typically need to access the properties of a button cell, as you can access the same properties through the button class.
In Cocoa, a button cell can be used for any region of a view that is designed to send a message to a target when clicked, although again, this isn’t a typical use for most AppleScript Studio applications. For related information, see the action cell, cell, and button class descriptions.
You can create and access a button cell in Interface Builder with the following steps:
Drag a button from the Cocoa-Controls pane of the Palette window to the target window.
Select the button.
Option-drag a resize handle of the button. As you drag, Interface Builder creates a matrix containing multiple button cells.
Clicking once selects the matrix; double-clicking selects a button cell within the matrix.
In addition to the properties it inherits from the cell class, a button cell object has these properties:
alternate image | ||||
| Access: | read/write | |||
| Class: | image | |||
the image for the cell when it is in its alternate state; see the Discussion section of the button class | ||||
alternate title | ||||
| Access: | read/write | |||
| Class: | Unicode text | |||
the title of the cell when it is in its alternate state see the Discussion section of the button class | ||||
bezel style | ||||
| Access: | read/write | |||
| Class: | enumerated constant from Bezel Style | |||
| the bezel style of the cell | ||||
button type | ||||
| Access: | read/write | |||
| Class: | enumerated constant from Button Type | |||
| the button type of the cell | ||||
highlights by | ||||
| Access: | read/write | |||
| Class: | integer (enumeration; equivalent of Behavior for a button in IB | |||
the mechanism by which the button is highlighted; most applications shouldn’t need to work with this property in their scripts and there are currently (through AppleScript Studio version 1.4) no AppleScript Studio enumerated constants defined for evaluating it; however, you can read about the Cocoa constants in the description for the NSCell class; you can set button behavior in Interface Builder using the Type and Behavior pop-ups in the Attributes pane of the Info window | ||||
image dims when disabled | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Does the image dim when the button is disabled? | ||||
key equivalent modifier | ||||
| Access: | read/write | |||
| Class: | integer | |||
the modifier key for the key equivalent; see the description for this property in the button class | ||||
roll over | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Does the button cell act like a roll over? | ||||
shows state by | ||||
| Access: | read/write | |||
| Class: | integer | |||
| not supported (through AppleScript Studio version 1.4); the way the button cell shows its state | ||||
sound | ||||
| Access: | read/write | |||
| Class: | sound | |||
| the sound played by the button cell when it is clicked | ||||
transparent | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Is the button cell transparent? | ||||
A button cell object supports handlers that can respond to the following events:
Action
clicked |
awake from nib |
AppleScript Studio applications typically script buttons, rather than scripting a button cell directly, and the button class has some of the same properties as the button
cell class. In addition, the button class inherits from the control class, which has a current
cell property, through which you can access properties of the button’s button cell, if necessary. For example, you can use the following script in Script Editor to access the button cell of a push button in the main window of an AppleScript Studio application. Similar statements will work within an AppleScript Studio application script (though you won’t need the tell
application statement).
tell application "testApplication" |
-- check the "image dims when disabled" property: |
image dims when disabled of (current cell of first button of window 1) |
-- result: 1 |
-- check transparency: |
transparent of (current cell of first button of window 1) |
-- result: 0 |
end tell |
The shows state by property in this class is not supported, through AppleScript Studio version 1.4.
Provides a mechanism for displaying text or images in a view without the overhead of a full NSView subclass.
Used by most control classes to implement their internal workings. Cell subclasses include action cell, button cell, image cell, and text field cell.
For more information, see the document Control and Cell Programming Topics for Cocoa.
A cell object has these properties:
action method | ||||
| Access: | read/write | |||
| Class: | Unicode text | |||
| the action method for the cell—a string representation of a Cocoa method selector | ||||
alignment | ||||
| Access: | read/write | |||
| Class: | enumerated constant from Text Alignment | |||
| the text alignment of the cell | ||||
allows editing text attributes | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Can the text attributes be edited? | ||||
allows mixed state | ||||
| Access: | read/write | |||
| Class: | boolean | |||
Does the cell allow a mixed state? see the description for this property in the button class | ||||
associated object | ||||
| Access: | read/write | |||
| Class: | item | |||
| the object associated with the cell | ||||
bezeled | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Does the cell have a bezel? | ||||
bordered | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Is the cell bordered? | ||||
cell size | ||||
| Access: | read only | |||
| Class: | point | |||
the size of the cell; the size is returned as a two-item list of numbers {horizontal, vertical}; for example, {75,
19} would indicate a width of 75 and a height of 19; see the bounds property of the window class for information on the coordinate system; for changes introduced in AppleScript Studio version 1.4, see the main discussion for the application class, as well as the coordinate system property of that class | ||||
cell type | ||||
| Access: | read/write | |||
| Class: | enumerated constant from Cell Type | |||
| the type of cell | ||||
content | ||||
| Access: | read/write | |||
| Class: | item | |||
the contents of the cell; nearly synonymous with contents; for related information, see the Version Notes section for this class | ||||
contents | ||||
| Access: | read/write | |||
| Class: | item | |||
the contents of the cell; nearly synonymous with content; for related information, see the Version Notes section for this class | ||||
continuous | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Does the cell generate actions as it is pressed? | ||||
control size | ||||
| Access: | read/write | |||
| Class: | enumerated constant from Control Size | |||
| the size of the control for the cell | ||||
control tint | ||||
| Access: | read/write | |||
| Class: | enumerated constant from Control Tint | |||
| the color of the control for the cell | ||||
control view | ||||
| Access: | read only | |||
| Class: | control | |||
| the control that the cell belongs to | ||||
double value | ||||
| Access: | read/write | |||
| Class: | real | |||
| the value of the contents as a double; 0.0 if the contents cannot be interpreted as a double | ||||
editable | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Is the cell editable? | ||||
enabled | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Is the cell enabled? | ||||
entry type | ||||
| Access: | read/write | |||
| Class: | integer | |||
| the entry type; the entry type is deprecated in Cocoa, so you should not use it in your scripts | ||||
float value | ||||
| Access: | read/write | |||
| Class: | real | |||
| the value of the contents as a float; 0.0 if the contents cannot be interpreted as a float | ||||
font | ||||
| Access: | read/write | |||
| Class: | font | |||
| the font of the cell | ||||
formatter | ||||
| Access: | read/write | |||
| Class: | formatter | |||
the formatter for the cell; this property is not supported (through AppleScript Studio version 1.4); however, see the Examples section of the formatter class for a description of how to use the call method command to get the formatter and extract information from it | ||||
has valid object value | ||||
| Access: | read only | |||
| Class: | boolean | |||
| Does the cell contain a valid value? a valid object value is one that the cell’s formatter (if one is present) can “understand” | ||||
highlighted | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Is the cell highlighted? | ||||
image | ||||
| Access: | read/write | |||
| Class: | image | |||
| the image of the cell | ||||
image position | ||||
| Access: | read/write | |||
| Class: | enumerated constant from Cell Image Position | |||
| the position of the image in the cell | ||||
imports graphics | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Should graphics be imported? | ||||
integer value | ||||
| Access: | read/write | |||
| Class: | integer | |||
| the value of the contents of the cell as an integer; 0 if the contents cannot be interpreted as an integer | ||||
key equivalent | ||||
| Access: | read only | |||
| Class: | Unicode text | |||
the key equivalent for the cell; see the description for this property in the button class | ||||
menu | ||||
| Access: | read/write | |||
| Class: | menu | |||
| the context menu for the cell, if any | ||||
mouse down state | ||||
| Access: | read only | |||
| Class: | integer | |||
| the state of the mouse when it was clicked in the cell | ||||
next state | ||||
| Access: | read/write | |||
| Class: | integer | |||
| the next state of the cell | ||||
opaque | ||||
| Access: | read only | |||
| Class: | boolean | |||
| Is the cell opaque? | ||||
scrollable | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Can the cell be scrolled? | ||||
selectable | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Is the cell selectable? | ||||
sends action when done editing | ||||
| Access: | read/write | |||
| Class: | boolean | |||
Should the cell send its action when it is done editing? Cocoa applications typically connect user interface objects to action methods of a target object, but AppleScript Studio applications connect them to event handlers in a script; however, you cannot connect any event handlers to a cell object | ||||
state | ||||
| Access: | read/write | |||
| Class: | enumerated constant from Cell State Value | |||
| the state of the cell | ||||
string value | ||||
| Access: | read/write | |||
| Class: | Unicode text | |||
| the value of the contents of the cell as text | ||||
tag | ||||
| Access: | read/write | |||
| Class: | integer | |||
| the tag of the cell | ||||
target | ||||
| Access: | read/write | |||
| Class: | item | |||
the target for the action of the cell; Cocoa applications typically connect user interface objects to action methods of a target object, but AppleScript Studio applications connect them to event handlers in a script; however, you cannot connect any event handlers to a cell object | ||||
title | ||||
| Access: | read/write | |||
| Class: | Unicode text | |||
| the title of the cell | ||||
wraps | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| Does the cell wrap? | ||||
Your script can send the following commands to a cell object:
perform action |
This class is not accessible in Interface Builder, and you cannot connect any event handlers to it.
You typically script a subclass of control or view that contains a cell (or a subclass of cell), not the cell itself. One situation where you might access a cell itself is when working with a matrix. A matrix is used to create groups of cell objects, such as radio buttons.
The Assistant application, available at <Xcode>/Examples/AppleScript Studio (starting with AppleScript Studio version 1.2) uses a matrix of radio buttons to specify the severity of a problem. It uses the following statement in its updateValues handler to get the title property of the currently selected radio button. This statement sets a property severity to the title of the current cell of the matrix (the matrix is also named “severity”):
set my severity to title of current cell of matrix "severity" |
The action method property was added in AppleScript Studio version 1.4. As a result, you can dynamically change the target of an action in your application or change the Cocoa method that is executed when the action is triggered. For an example of how to do this, see the toolbar item class.
The content property was added in AppleScript Studio version 1.2. You can use content and contents interchangeably, with one exception. Within an event handler, contents
of theObject returns a reference to an object, rather than the actual contents. To get the actual contents of an object (such as the text contents from a text field) within an event handler, you can either use contents
of contents of theObject or content
of theObject.
The formatter property in this class is not supported, through AppleScript Studio version 1.4.
For a sample script that shows the difference between content and contents, see the Version Notes section for the control class.
Supports selecting and displaying a single color value.
A color-panel uses a color well to display the current color selection. You typically work with colors through the color panel property of the application class, not by working directly with a color well.
Figure 4-2 shows a color well in a window. Clicking the color well opens a color panel; choosing a color in the color panel sets the color in the color well.
You will find the color well object on the Cocoa-Controls pane of Interface Builder’s Palette window. You can set attributes for color wells in Interface Builder’s Info window.
For related information, see the document Color Programming Topics for Cocoa.
In addition to the properties it inherits from the control class, a color well object has these properties:
A color well object supports handlers that can respond to the following events:
Action
clicked
| ||||
Clicking a color well automatically opens a | ||||
conclude drop | ||||
drag | ||||
drag entered | ||||
drag exited | ||||
drag updated | ||||
drop | ||||
prepare drop |
keyboard 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 |
bounds changed |
You typically work with colors through the color
panel property of the application class, not by working directly with a color well. For examples, see color-panel.
Support for drag-and-drop commands was added in AppleScript Studio version 1.2.
A control that provides two ways to enter a value: through direct text entry (as with a text field), or by choosing from a pop-up list of pre-selected values.
Figure 4-3 shows a combo box with its pop-up list hidden.
Figure 4-4 shows the same combo box with its pop-up list displayed.
You will find the combo box object on the Cocoa-Text pane of Interface Builder’s Palette window. You can set many attributes for combo boxes in Interface Builder’s Info window. Note that through AppleScript Studio version 1.4, you cannot use a data source object with a combo box.
For more information, see the document Combo Boxes.
In addition to the properties it inherits from the text field class, a combo box object has these properties:
auto completes | ||||
| Access: | read/write | |||
| Class: | boolean | |||
Does the combo box use auto completion when typing? default is false; can be set in Info window in Interface Builder | ||||
current item | ||||
| Access: | read/write | |||
| Class: | integer | |||
| the index of the current item, base 0 | ||||
data source | ||||
| Access: | read/write | |||
| Class: | data source | |||
| not supported (through AppleScript Studio version 1.4); the data source for the combo box; you can set this property in the Info window in Interface Builder | ||||
has vertical scroller | ||||
| Access: | read/write | |||
| Class: | boolean | |||
Does the combo box have a vertical scroll bar? default is true; can set Scrollable in Info window in Interface Builder | ||||
intercell spacing | ||||
| Access: | read/write | |||
| Class: | list | |||
| the horizontal and vertical spacing between cells in the combo box’s list; represented as a two-item list of numbers; default is {3,2} | ||||
item height | ||||
| Access: | read/write | |||
| Class: | real | |||
| the height of an item | ||||
uses data source | ||||
| Access: | read/write | |||
| Class: | boolean | |||
| not supported (through AppleScript Studio version 1.4); Does the combo box use a data source for its items? you can set this property in the Info window in Interface Builder | ||||
In addition to the elements it inherits from the text field class, a combo
box object can contain the elements listed below. Your script can access most elements with any of the key forms described in