< Previous PageNext Page > Hide TOC

Control View Suite

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.

Terminology

The classes, commands, and events in the Control View suite are described in the following sections:

For enumerated constants, see “Enumerations.”

Classes

The Control View suite contains the following classes:

action cell
Plural: action cells
Inherits from: cell
Cocoa Class: NSActionCell

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.

Events supported by action cell objects

This class is not accessible in Interface Builder, and you cannot connect any event handlers to it.

Examples

See the examples for cell.

button
Plural: buttons
Inherits from: control
Cocoa Class: NSButton

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.


Figure 4-1  A button

A 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.

Properties of button objects

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?


Elements of button objects

A button object can contain only the elements it inherits from control.

Commands supported by button objects

Your script can send the following command to a button object:

highlight

Events supported by button objects

A button object supports handlers that can respond to the following events:

Action
clicked

Drag and Drop
conclude drop
drag
drag entered
drag exited
drag updated
drop
prepare drop

Key
keyboard down
keyboard up

Mouse
mouse down
mouse dragged
mouse entered
mouse exited
mouse up
right mouse down
right mouse dragged
right mouse up
scroll wheel

Nib
awake from nib

View
bounds changed

Examples

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
Discussion

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:

  1. 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.

  2. 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.

  3. 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.

  4. Set the Behavior pop-up to Toggle.

  5. Type “Start” in the Title field and “Stop” in the Alt. Title field.

  6. 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.

button cell
Plural: button cells
Inherits from: cell
Cocoa Class: NSButtonCell

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:

  1. Drag a button from the Cocoa-Controls pane of the Palette window to the target window.

  2. Select the button.

  3. Option-drag a resize handle of the button. As you drag, Interface Builder creates a matrix containing multiple button cells.

  4. Clicking once selects the matrix; double-clicking selects a button cell within the matrix.

Properties of button cell objects

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?


Events supported by button cell objects

A button cell object supports handlers that can respond to the following events:

Action
clicked

Nib
awake from nib

Examples

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
Version Notes

The shows state by property in this class is not supported, through AppleScript Studio version 1.4.

cell
Plural: cells
Inherits from: None.
Cocoa Class: NSCell

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.

Properties of cell objects

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?


Commands supported by cell objects

Your script can send the following commands to a cell object:

perform action

Events supported by cell objects

This class is not accessible in Interface Builder, and you cannot connect any event handlers to it.

Examples

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"
Version Notes

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.

color well
Plural: color wells
Inherits from: control
Cocoa Class: NSColorWell

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.


Figure 4-2  A color well in a window

A color well in a window

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.

Properties of color well objects

In addition to the properties it inherits from the control class, a color well object has these properties:

active
 Access:read/write
 Class:boolean
 Is the color well active?
bordered
 Access:read/write
 Class:boolean
 Does the color well have a border?
color
 Access:read/write
 Class:RGB color
 the color in the well; a three-item integer list that contains the values for each component of the color; for example, red can be represented as {65535,0,0}


Events supported by color well objects

A color well object supports handlers that can respond to the following events:

Action
clicked
 

Clicking a color well automatically opens a color-panel, and your clicked handler will only be called the first time the color well is clicked.


Drag and Drop
conclude drop
drag
drag entered
drag exited
drag updated
drop
prepare drop

Key
keyboard down
keyboard up

Mouse
mouse down
mouse dragged
mouse entered
mouse exited
mouse up
right mouse down
right mouse dragged
right mouse up
scroll wheel

Nib
awake from nib

View
bounds changed

Examples

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.

Version Notes

Support for drag-and-drop commands was added in AppleScript Studio version 1.2.

combo box
Plural: combo boxes
Inherits from: text field
Cocoa Class: NSComboBox

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-3  A combo box, with no pop-up list showing

A combo box, with no pop-up list showing

Figure 4-4 shows the same combo box with its pop-up list displayed.


Figure 4-4  A combo box, with the pop-up list displayed

A combo box, with the 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 Box Programming Topics.

Properties of combo box objects

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


Elements of combo box objects

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 “Standard Key Forms.”

combo box item
 Specify by: “Standard Key Forms”
 

represent items in the combo box’s pop-up list; stored as a simple list of text items


Commands supported by combo box objects

Your script can send the following commands to a combo box class object:

scroll

Events supported by combo box objects

An object of class combo box supports handlers that can respond to the following events:

Action
action

Combo Box
selection changed
selection changing
will dismiss
will pop up

Drag and Drop
conclude drop
drag
drag entered
drag exited
drag updated
drop
prepare drop

Editing
begin editing
changed
end editing
should begin editing
should end editing

Key
keyboard up

Mouse
mouse entered
mouse exited
scroll wheel

Nib
awake from nib

View
bounds changed

Examples

You can access the items in the pop-up list of a combo box through its combo box item property. Given a combo box with AppleScript name “combo” in the window “main”, the following statement will return a simple list of text items, each representing one item in the pop-up list of the combo box:

every combo box item of combo box "combo" of window "main"

The following lines will delete all the items in the combo box and add one new item:

delete every combo box item of combo box "combo" of window  "main"
make new combo box item at end of combo box items of combo box "combo"  of
    window "main" with data "Test Item"

You can delete a combo box item by index with a statement like the following:

delete combo box item 2 of combo box 1 of window 1

To get the contents of a combo box (the value in the text field part of the combo box), you can use a statement like the following:

set comboContents to contents of combo box "combo" of  window "main"

See also the Examples section for the combo box item class.

Version Notes

The following properties in this class are not supported, through AppleScript Studio version 1.4:

Support for drag-and-drop commands was added in AppleScript Studio version 1.2.

combo box item
Plural: combo box items
Inherits from: None.
Cocoa Class: ASKComboBoxItem

Represents one item in the pop-up list of a combo box.

For related information, see combo box.

Events supported by combo box item objects

This class is not accessible in Interface Builder, and you cannot connect any event handlers to it.

Examples

Given a combo box with AppleScript name “combo” in the front window, the following statement will return a simple list of text items, each representing one item in the pop-up list of the combo box:

every combo box item of combo box "combo" of window 1

See the Examples section for the combo box class for information on creating and deleting combo box items.

Version Notes

The combo box item class was added in AppleScript Studio version 1.1.

control
Plural: controls
Inherits from: view
Cocoa Class: NSControl

An abstract superclass that provides three fundamental features for implementing user-interface devices (such as buttons, scrollers, sliders, text fields, and so on): drawing devices onscreen, responding to user events, and sending action messages.

Works closely with cell objects. Most applications won’t often need to script a control directly—rather they script subclasses, such as button or text field.

For more information, see the document Control and Cell Programming Topics for Cocoa.

Properties of control objects

In addition to the properties it inherits from the view class, a control object has these properties:

action method
 Access:read/write
 Class:Unicode text
 the action method for the control—a string representation of a Cocoa method selector
alignment
 Access:read/write
 Class:enumerated constant from Text Alignment
 the text alignment of the control
cell
 Access:read/write
 Class:cell
 the cell of the control
content
 Access:read/write
 Class:item
 the value of the control; nearly synonymous with contents; for related information, see the Version Notes section for this class
contents
 Access:read/write
 Class:item
 the value of the control; nearly synonymous with content; for related information, see the Version Notes section for this class
continuous
 Access:read/write
 Class:boolean
 Does the control continuously generate actions?
current cell
 Access:read only
 Class:cell
 the current cell of the control
current editor
 Access:read/write
 Class:text or text view
 the current editor, if the control is being edited; if not, returns nil; typically returns a value such as current field editor of window id 1 of application "StudioTest"; see the field editor property of the text class for a description of an editor
double value
 Access:read/write
 Class:real
 the value of the control as a double; 0.0 if the contents cannot be interpreted as a double
enabled
 Access:read/write
 Class:boolean
 Is the control enabled?
float value
 Access:read/write
 Class:real
 the value of the control as a float; 0.0 if the contents cannot be interpreted as a float
font
 Access:read/write
 Class:font
 the font of the control
formatter
 Access:read/write
 Class:formatter
 the formatter of the control; 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
ignores multiple clicks
 Access:read/write
 Class:boolean
 Does the control ignore multiple clicks?
integer value
 Access:read/write
 Class:integer
 the value of the control as an integer; 0 if the contents cannot be interpreted as an integer
string value
 Access:read/write
 Class:Unicode text
 the value of the control as text
target
 Access:read/write
 Class:item
 the target of the control's action


Elements of control objects

A control object can contain only the elements it inherits from view.

Commands supported by control objects

Your script can send the following commands to a control object:

perform action

Events supported by control objects

This class is not accessible in Interface Builder, and you cannot connect any event handlers to it.

Examples

The control class is an abstract class that you don’t typically target in your scripts. More often you target subclasses, such as button or slider.

Version Notes

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.

The following listing of an action handler uses the log command to show the result of using content and contents on a text field that contains the text “Some text”.

on action theObject
    log theObject -- result: text field 1 of window 1
    log contents of theObject -- result: text field 1 of window  1
    log contents of contents of theObject as string
        -- result: "Some text"
    log content of theObject as string
        -- result: "Some text"
end action
image cell
Plural: image cells
Inherits from: cell
Cocoa Class: NSImageCell

Displays a single image in a frame.

Provides properties for specifying the frame style and aligning and scaling the image. An image cell is usually associated with some kind of control class, such as image view, matrix, or table view.

You can create and access an image cell in Interface Builder with the following steps:

  1. Drag an image view from the Cocoa-Controls pane of the Palette window to the target window.

  2. Select the image view.

  3. Option-drag a resize handle of the image view. As you drag, Interface Builder creates a matrix containing multiple image cells.

  4. Clicking once selects the matrix; double-clicking selects an image cell within the matrix.

For more information, see image, as well as the Cocoa topics Image Views, Matrix Programming Guide for Cocoa, and Table View Programming Guide.

Properties of image cell objects

In addition to the properties it inherits from the cell class, an image cell object has these properties:

image alignment
 Access:read/write
 Class:enumerated constant from Image Alignment
 the alignment of the image for the cell
image frame style
 Access:read/write
 Class:enumerated constant from Image Frame Style
 the frame style of the image
image scaling
 Access:read/write
 Class:enumerated constant from Image Scaling
 the scaling of the image


Events supported by image cell objects

An image cell object supports handlers that can respond to the following events:

Action
clicked

Nib
awake from nib

Examples

You don’t typically script an image cell. You can script similar properties (frame style, alignment, scaling) of an image view instead.

image view
Plural: image views
Inherits from: control
Cocoa Class: NSImageView

Displays a single image in a frame, and can optionally allow a user to drag an image to it.

Figure 4-5 shows an image displayed in an image view by the Image sample application, available at <Xcode>/Examples/AppleScript Studio.

You can store an image in your AppleScript Studio project by dragging an image file from the Finder into one of the groups in the Files list in Xcode’s Groups & Files list, or by using the Add Files… command from the Project menu. You can also drag images into the Images pane of a nib window in Interface Builder. You can display an image in an image view by loading it with load image command. For related information, see image, as well as the document Image Views.

If you continually load images and don’t free them, your application memory usage will increase. For information on how to free an image, movie, or sound, see the Discussion section of the load image command.


Figure 4-5  A window displaying an image in an image view (from the Image sample application)

A window displaying an image in an image view (from the Image sample application)

Properties of image view objects

In addition to the properties it inherits from the control class, an image view object has these properties:

editable
 Access:read/write
 Class:boolean
 Is the image view editable? default is false; you can set this property in the Info window in Interface Builder
image
 Access:read/write
 Class:image
 the image for the view; you can set this property in Interface Builder by dragging an image onto the image view
image alignment
 Access:read/write
 Class:enumerated constant from Image Alignment
 the alignment for the image; default is center alignment; you can set this property in the Info window in Interface Builder
image frame style
 Access:read/write
 Class:enumerated constant from Image Frame Style
 the frame style of the image; you can set this property in the Info window in Interface Builder
image scaling
 Access:read/write
 Class:enumerated constant from Image Scaling
 the scaling of the image; default is scale proportionally; you can set this property in the Info window in Interface Builder


Elements of image view objects

An image view object can contain only the elements it inherits from control.

Events supported by image view objects

An image view object supports handlers that can respond to the following events:

Action
clicked

Drag and Drop
conclude drop
drag
drag entered
drag exited
drag updated
drop
prepare drop

Key
keyboard down
keyboard up

Mouse
mouse down
mouse dragged
mouse entered
mouse exited
mouse up
right mouse down
right mouse dragged
right mouse up
scroll wheel

Nib
awake from nib

View
bounds changed

Examples

The following awake from nib handler is from the Image sample application, available at <Xcode>/Examples/AppleScript Studio. The handler simply uses the load image command to load an image from the project. (The image is stored in the project’s Resources group and is named AboutBox.tiff.)

on awake from nib theObject
    set image of image view "image" of window "main"  to load image "AboutBox"
end awake from nib

If you continually load images and don’t free them, your application memory usage will increase. For information on how to free an image, movie, or sound, see the Discussion section of the load image command.

matrix
Plural: matrices
Inherits from: control
Cocoa Class: NSMatrix

Used to create groups of cell objects, such as radio buttons, that work together in various ways.

Figure 4-6 shows a matrix that contains three radio buttons.


Figure 4-6  A matrix with three radio buttons

A matrix with three radio buttons

You will find the matrix object (containing radio buttons) on the Cocoa-Controls pane of Interface Builder’s Palette window. You can set many attributes for matrix objects in Interface Builder’s Info window. For information on creating matrix objects that contain other kinds of objects, see the scroll view class, as well as the button cell, image cell, secure text field cell, and text field cell classes.

For more information, see the document Matrix Programming Guide for Cocoa.

Properties of matrix objects

In addition to the properties it inherits from the control class, a matrix object has these properties:

allows empty selection
 Access:read/write
 Class:boolean
 Does the matrix allow an empty selection? default is false, for example, for a matrix of radio buttons; you can set this property in the Info window in Interface Builder
auto scroll
 Access:read/write
 Class:boolean
 Should the matrix automatically scroll?
auto sizes cells
 Access:read/write
 Class:boolean
 Should the matrix auto size its cells? default is false for a matrix of radio buttons; you can set this property in the Info window in Interface Builder
background color
 Access:read/write
 Class:RGB color
 the background color of the matrix; a three-item integer list that contains the values for each component of the color; for example, red can be represented as {65535,0,0}; by default, {65535, 65535, 65535}, or white; you can set this property in the Info window in Interface Builder
cell background color
 Access:read/write
 Class:RGB color
 the background color of the cells in the matrix; a three-item integer list that contains the values for each component of the color; by default, {65535, 65535, 65535}, or white
cell size
 Access:read/write
 Class:point
 the size of each cell in the matrix; the size is returned as a two-item list of numbers {horizontal, vertical}; see the bounds property of the window class for information on the coordinate system; not supported (through AppleScript Studio version 1.4); however, there is a workaround that uses the call method command to get or set this property; the first statement below gets the size—the second statement sets it:
 set cellSize to call method "cellSize" of matrix 1 of window 1
 call method "setCellSize:" of matrix 1 of window 1 with parameter {200, 20}
current cell
 Access:read/write
 Class:cell
 the current cell
current column
 Access:read/write
 Class:integer
 the one-based current column of the matrix
current row
 Access:read/write
 Class:integer
 the one-based current row of the matrix
draws background
 Access:read/write
 Class:boolean
 Should the matrix draw its background? default is false for a matrix of radio buttons; you can set this property in the Info window in Interface Builder
draws cell background
 Access:read/write
 Class:boolean
 Should the cells of the matrix draw their background?
intercell spacing
 Access:read/write
 Class:list
 the vertical and horizontal spacing between cells in the matrix; by default, both values are 1.0 in the coordinate system of the matrix (see the bounds property of the window class for information on the coordinate system); not supported (through AppleScript Studio version 1.4); however, there is a workaround that uses the call method command to get or set this property; the first statement below gets the spacing—the second statement sets it:
 
set spacing to call method "intercellSpacing" of matrix  1 of window 1
call method "setIntercellSpacing:" of matrix 1 of window  1 with parameter {2.0,  2.0}
key cell
 Access:read/write
 Class:cell
 the key cell of the matrix
matrix mode
 Access:read/write
 Class:enumerated constant from Matrix Mode
 the mode of the matrix (for example, radio mode)
next text
 Access:read/write
 Class:anything
 not supported (through AppleScript Studio version 1.4); use of the method in Cocoa’s NSMatrix class that this property is based on is no longer encouraged, so this property is not likely to ever be supported; the next editor of the matrix; see the field editor property of the text class for a description of an editor
previous text
 Access:read/write
 Class:anything
 not supported (through AppleScript Studio version 1.4); use of the method in Cocoa’s NSMatrix class that this property is based on is no longer encouraged, so this property is not likely to ever be supported; the previous editor of the matrix
prototype cell
 Access:read/write
 Class:cell
 the prototype cell of the matrix
scrollable
 Access:read/write
 Class:boolean
 Is the matrix scrollable? not supported (through AppleScript Studio version 1.4); however, there is a workaround that uses the call method command to set this property (though not to get it); note that you must pass a boolean value to the call method command as a one-item list:
 
call method "setScrollable:" of matrix 1 of window 1 with  parameters {true}
selection by rect
 Access:read/write
 Class:boolean
 Can cells be selected by rect? you can set this property in the Info window in Interface Builder
tab key traverses cells
 Access:read/write
 Class:boolean
 Does the tab key traverse cells?


Elements of matrix objects

In addition to the properties it inherits from the control, a matrix object can contain the elements listed below. Your script can access most elements with any of the key forms described in “Standard Key Forms.”

cell
 Specify by: “Standard Key Forms”
 

the matrix’s cells


Events supported by matrix objects

A matrix object supports handlers that can respond to the following events:

Action
clicked

Drag and Drop
conclude drop
drag
drag entered
drag exited
drag updated
drop
prepare drop

Key
keyboard down
keyboard up

Mouse
mouse down
mouse dragged
mouse entered
mouse exited
mouse up
right mouse down
right mouse dragged
right mouse up
scroll wheel

Nib
awake from nib

View
bounds changed

Examples

The Drawer sample application distributed with AppleScript Studio uses a matrix that contains four radio buttons to specify the side on which its drawer should open (left, top, right, or bottom). The following statements, from the application’s awake from nib handler, set the current row of the matrix to indicate the currently selected radio button, based on edge information from the drawer.

on awake from nib theObject
    tell theObject
        set openOnEdge to edge of drawer "drawer"
        ...
        if openOnEdge is left edge then
            set current row of matrix "open on" to 1
        else if openOnEdge is top edge then
            set current row of matrix "open on" to 2
        else if openOnEdge is right edge then
            set current row of matrix "open on" to 3
        else if openOnEdge is bottom edge then
            set current row of matrix "open on" to 4
        end if
        ...
    end tell
end awake from nib

The following statements, from the same application’s clicked handler, show how to extract row information from the matrix, so that when the “drawer” button is clicked, the application knows on which side to open the drawer.

on clicked theObject
    tell window "main"
        if theObject is equal to button "drawer" then
            ...
            set openOnSide to current row of matrix "open on"
    ...
Version Notes

The following properties in this class are not supported, through AppleScript Studio version 1.4:

Support for drag-and-drop commands was added in AppleScript Studio version 1.2.

movie view
Plural: movie views
Inherits from: view
Cocoa Class: NSMovieView

Displays a movie in a frame and provides properties associated with playing and editing the movie.

You use the load movie command to load a movie for the movie view. For playing, stepping through, or jumping to a location in the movie, you use commands such as start, stop, play, step forward, step back, and go (to jump to a specified location).

Figure 4-7 shows a movie displayed in a movie view in the Talking Head sample application, available at <Xcode>/Examples/AppleScript Studio.

You can store a movie in your AppleScript Studio project by dragging a movie file from the Finder into one of the groups in the Files list in Xcode’s Groups & Files list, or by using the Add Files… command from the Project menu. You can display a movie in a movie view by loading it with load movie command.

You can insert a movie view object into a nib file in Interface Builder by dragging the object represented by the QuickTime symbol from the Cocoa-GraphicsViews pane of the Palette window to the target window.


Figure 4-7  A movie view (from the Talking Head sample application)

A movie view (from the Talking Head sample application)

Properties of movie view objects

In addition to the properties it inherits from the view class, a movie view object has these properties:

controller visible
 Access:read/write
 Class:boolean
 Is the controller visible? default is true; you can set this property in the Info window in Interface Builder
editable
 Access:read/write
 Class:boolean
 Is the movie editable? default is true; you can set this property in the Info window in Interface Builder
loop mode
 Access:read/write
 Class:enumerated constant from QuickTime Movie Loop Mode
 the loop mode of the player; default is normal; you can set this property in the Info window in Interface Builder
movie
 Access:read/write
 Class:movie
 the movie for the view to play; you load the movie in your script with the load movie command
movie controller
 Access:read only
 Class:item
 the QuickTime movie controller
movie file
 Access:read/write
 Class:Unicode text
 the POSIX-style (slash-delimited) path to the movie file for the movie view; see the class description above for information on adding movies to your AppleScript Studio project
movie rect
 Access:read/write
 Class:bounding rectangle
 the bounds of the movie in the view; a list of four numbers {left, bottom, right, top}; 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
muted
 Access:read/write
 Class:boolean
 Is the movie muted? default is false
playing
 Access:read/write
 Class:boolean
 Is the movie playing?
plays every frame
 Access:read/write
 Class:boolean
 Should the movie play every frame? default is false; you can set this property in the Info window in Interface Builder
plays selection only
 Access:read/write
 Class:boolean
 Should the player only play the selected portions of the movie? default is false; you can set this property in the Info window in Interface Builder
rate
 Access:read/write
 Class:real
 the rate at which to play the movie
volume
 Access:read/write
 Class:real
 the volume of the movie; for more information on volume, see the Examples section for the slider class


Commands supported by movie view objects

Your script can send the following commands to a movie view object:

copy (from Cocoa’s Standard suite)
go
play
pause
start
step back
step forward
stop

Events supported by movie view objects

A movie view object supports handlers that can respond to the following events:

Drag and Drop
conclude drop
drag
drag entered
drag exited
drag updated
drop
prepare drop

Key
keyboard down
keyboard up

Mouse
mouse down
mouse dragged
mouse entered
mouse exited
mouse up
right mouse down
right mouse dragged
right mouse up
scroll wheel

Nib
awake from nib

View
bounds changed

Examples

The following will open handler is from the Talking Head sample application, available at <Xcode>/Examples/AppleScript Studio. The handler simply uses the load movie command to load a movie from the project when the window that contains a movie view is opened. (The image is stored in the project’s Resources group and is named jumps.mov.)

on will open theObject
    set movie of movie view "movie" of window "main"  to load movie "jumps"
end will open

If you continually load movies and don’t free them, your application memory usage will increase. For information on how to free an image, movie, or sound, see the Discussion section of the load image command.

Version Notes

Support for drag-and-drop commands was added in AppleScript Studio version 1.2.

popup button
Plural: popup buttons
Inherits from: button
Cocoa Class: NSPopUpButton

Provides access to a pop-up menu or a pull-down menu, from which a user can choose an item.

Figure 4-8 shows a popup button displaying the first menu item in the pop-up menu.


Figure 4-8  A popup button

A popup button

You will find the popup button object on the Cocoa-Controls pane of Interface Builder’s Palette window. You can set attributes for popup buttons in Interface Builder’s Info window.

For related information, see the document Application Menu and Pop-up List Programming Topics for Cocoa.

Properties of popup button objects

In addition to the properties it inherits from the button class, a popup button object has these properties:

auto enables items
 Access:read/write
 Class:boolean
 Should the items in the menu be automatically enabled? default is true; you can set this property in the Info window in Interface Builder
current menu item
 Access:read/write
 Class:menu item
 the currently chosen menu item
preferred edge
 Access:read/write
 Class:enumerated constant from Rectangle Edge
 the preferred edge to present the menu under severe screen position restrictions; note that the preferred edge will be ignored if there is not enough room to pop up the menu in that direction
pulls down
 Access:read/write
 Class:boolean
 Does the menu pull down? default is false; you can set this property in the Info window in Interface Builder


Elements of popup button objects

In addition to the elements it inherits from the button class, a popup button object can contain the elements listed below. Your script can access most elements with any of the key forms described in “Standard Key Forms.”

menu
 Specify by: “Standard Key Forms”
 

the popup button’s submenus

menu item
 Specify by: “Standard Key Forms”
 

the popup button’s menu items


Commands supported by popup button objects

Your script can send the following commands to a popup button:

synchronize

Events supported by popup button objects

An popup button supports handlers that can respond to the following events:

Action
action

Drag and Drop
conclude drop
drag
drag entered
drag exited
drag updated
drop
prepare drop

Key
keyboard down
keyboard up

Menu
choose menu item
will pop up

Mouse
mouse entered
mouse exited
right mouse down
right mouse dragged
right mouse up
scroll wheel

Nib
awake from nib

View
bounds changed

Examples

For examples that show how to work with a popup button and respond to user changes, see the sample applications Coordinate System, Task List, and Unit Converter, available at <Xcode>/Examples/AppleScript Studio.

The following statement, from the awake from nib handler of the Task List sample application (available starting with AppleScript Studio version 1.2) sets the title of a popup button with AppleScript name “priority” to “3”.

set title of popup button "priority" to "3"

You remove menu items from a popup button with the delete command and insert them with the make command. For example, in the file Converter.applescript of the Unit Converter sample application distributed with AppleScript Studio, you'll find the updateUnitTypes handler. This handler shows how to delete all the items in the pop-up menu associated with a popup button and replace them with new items when you need to update the items in the menu.

    on updateUnitTypes()
        tell box 1 of window "Main"
            -- Delete all of the menu items from the pop-ups
            delete every menu item of menu of popup button "From"
            delete every menu item of menu of popup button "To"
 
            -- Add each of the unit types as menu items to both  of the pop-ups
            repeat with i in my unitTypes
                make new menu item at the end of menu items of menu  of
                    popup button "From"
                    with properties {title:i, enabled:true}
                make new menu item at the end of menu items of menu
                    of popup button "To"
                    with properties {title:i, enabled:true}
            end repeat
        end tell
    end updateUnitTypes

You can get the current menu item in a popup button with a statement like the following:

current menu item of popup button 1 of window 1

You can set the current menu item in a popup button with a statement like the following:

set current menu item of popup button 1 of window 1 to menu item  2 of menu of  popup button 1 of window 1

You can get the zero-based index of the currently selected menu item in a popup button with a statement like the following:

set currentIndex to contents of popup button 1 of window 1

You can get the value of the currently selected menu item in a popup button with a statement like the following:

set currentValue to title of popup button 1 of window 1

You can delete a named menu item from a named popup button with a statement like the following:

delete menu item "Shrink It" of menu of popup button "Do  Laundry" of window  "Laundromat"
Version Notes

Support for drag-and-drop commands was added in AppleScript Studio version 1.2.

Starting with AppleScript Studio version 1.2, when referring to the menu of a popup button, a script can say menu item 1 of popup button 1 instead of the longer menu item 1 of menu of popup button 1, although the longer form still works.

progress indicator
Plural: progress indicators
Inherits from: view
Cocoa Class: NSProgressIndicator

A progress indicator (also known as a progress bar) provides a standard mechanism for user feedback. Combined with a text field, it can provide both determinate (the total time is known and the bar moves from left to right proportional to the percentage of the task completed) and indeterminate (the total time is not known, and a striped cylinder or circular image spins continually) progress bars, as well as text messages.

Figure 4-9 shows an indeterminate progress indicator.


Figure 4-9  An indeterminate progress indicator

An indeterminate progress indicator

You will find the progress indicator on the Cocoa-Controls pane of Interface Builder’s Palette window. Starting with the version of Interface Builder released with Mac OS X version 10.2, you can also choose the circular indeterminate progress indicator shown in Figure 4-10. This type of progress indicator is often used for activity such as connecting to a network.

You can set attributes for progress indicators in Interface Builder’s Info window.


Figure 4-10  A circular indeterminate progress indicator

A circular indeterminate progress indicator

Properties of progress indicator objects

In addition to the properties it inherits from the view class, a progress indicator object has these properties:

animation delay
 Access:read/write
 Class:integer
 the amount to delay between animations; default is 0
bezeled
 Access:read/write
 Class:boolean
 Is the progress indicator bezeled? default is false
content
 Access:read/write
 Class:real
 the value of the progress indicator; nearly synonymous with contents; for related information, see the Version Notes section for this class
contents
 Access:read/write
 Class:real
 the value of the progress indicator; nearly synonymous with content; for related information, see the Version Notes section for this class
control size
 Access:read/write
 Class:enumerated constant from Control Size
 the size of the progress indicator; default is regular size; you can set this property in the Info window in Interface Builder
control tint
 Access:read/write
 Class:enumerated constant from Control Tint
 the tint of the progress indicator; default is default tint
indeterminate
 Access:read/write
 Class:boolean
 Is the value of the progress indicator indeterminate? (an indeterminate progress indicator spins; a determinate progress indicator shows the percentage completed for the task); you can set this property in the Info window in Interface Builder
maximum value
 Access:read/write
 Class:real
 the maximum value of the progress indicator; default is 100.0; you can set this property in the Info window in Interface Builder
minimum value
 Access:read/write
 Class:real
 the minimum value of the progress indicator; default is 0.0; you can set this property in the Info window in Interface Builder
uses threaded animation
 Access:read/write
 Class:boolean
 Should animation of this progress indicator be performed in a separate thread? if the application becomes multithreaded as a result of an invocation of this, the application's performance could become noticeably slower; default is false


Commands supported by progress indicator objects

Your script can send the following commands to a progress indicator object:

animate
increment
start
stop

Events supported by progress indicator objects

A progress indicator object supports handlers that can respond to the following events:

Drag and Drop
conclude drop
drag
drag entered
drag exited
drag updated
drop
prepare drop

Mouse
mouse down
mouse dragged
mouse entered
mouse exited
mouse up
right mouse down
right mouse dragged
right mouse up
scroll wheel

Nib
awake from nib

View
bounds changed

Examples

For brief examples of commands you use with progress indicators, see the animate, increment, start, and stop commands.

The following openPanel handler is from the Mail Search sample application, available at <Xcode>/Examples/AppleScript Studio. (Prior to AppleScript Studio version 1.1, Mail Search was named Watson.) This handler is one of several handlers that are part of a script object defined in the Mail Search application to control the status panel window.

The handler has one parameter, statusMessage, which supplies a message to display in the status panel. It also relies on global and script properties, including initialized and statusPanelNibLoaded.

If the status panel window hasn’t already been loaded, the handler loads it, sets the state of the window’s progress indicator, tells the indicator to start, and sets a text message for the status panel. It then uses the display command to display the status panel (and its progress indicator) attached to another window.

        on openPanel(statusMessage)
            if initialized is false then
                if not statusPanelNibLoaded then
                    load nib "StatusPanel"
                    set statusPanelNibLoaded to true
                end if
                tell window "status"
                    set indeterminate of progress indicator "progress"
                        to true
                    tell progress indicator "progress"  to start
                    set contents of text field "statusMessage"
                        to statusMessage
                end tell
                set initialized to true
            end if
            display window "status" attached to theWindow
        end openPanel

The Mail Search application also demonstrates a determinate progress indicator. Look for the makeStatusPanel handler, which creates and returns a script object with handlers to load a status panel containing the progress indicator, set its minimum and maximum values, and tell it to increment. The Mail Search Application is described in detail in AppleScript Studio Programming Guide (see “See Also” for information on that document).

Version Notes

Support for drag-and-drop commands was added in AppleScript Studio version 1.2.

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.

For a sample script that shows the difference between content and contents, see the Version Notes section for the control class.

Starting with AppleScript Studio version 1.2, the display command is preferred over the display panel command.

Starting with the version of Interface Builder released with Mac OS X version 10.2, you can use the circular indeterminate progress indicator shown in Figure 4-10.

Prior to AppleScript Studio version 1.1, the Mail Search sample application was named Watson.

secure text field
Plural: secure text fields
Inherits from: text field
Cocoa Class: NSSecureTextField

Hides its text from display or other access via the user interface, and is thus suitable for use as a password-entry object, or for any item in which a secure value must be kept.

A user can drop text into a secure text field, but it will be displayed according to the current settings of the field—either as bullets as blank characters. The default is to display text as bullets. For information on how to specify blanks, see the Examples section of the secure text field cell class.

Figure 4-11 shows a secure text field with several bullets visible. You can create a secure text field in Interface Builder with the following steps:

  1. Drag a text field from the Cocoa-Text pane of the Palette window to the target window.

  2. Select the text field.

  3. In the Custom Class pane of the Info window, select NSSecureTextField as the class type.


Figure 4-11  A secure text field showing several bullets

A secure text field showing several bullets

For more information, see the class descriptions for text field cell and secure text field cell, as well as the document Text Fields.

Properties of secure text field objects

A secure text field object has only the properties it inherits from text field.


Elements of secure text field objects

A secure text field object can contain only the elements it inherits from text field.

Events supported by secure text field objects

A secure text field object supports handlers that can respond to the following events:

Action
action

Drag and Drop
conclude drop
drag
drag entered
drag exited
drag updated
drop
prepare drop

Editing
begin editing
changed
end editing
should begin editing
should end editing

Key
keyboard up

Mouse
mouse entered
mouse exited
scroll wheel

Nib
awake from nib

View
bounds changed

Examples

A secure text field has no scriptable properties or elements of its own. However, it inherits all of the properties and elements of text field. See also secure text field cell.

Version Notes

Support for drag-and-drop commands was added in AppleScript Studio version 1.2.

secure text field cell
Plural: secure text field cells
Inherits from: text field cell
Cocoa Class: NSSecureTextFieldCell

Works with a secure text field object to provide a text field whose value is guarded from user examination.

Provides its own field editor, which doesn't display text or allow a user to Cut, Copy, or Paste its value. However, you can drag and drop text into a secure text field.

For more information, see secure text field, as well as the document Text Fields.

You can create and access a secure text field cell in Interface Builder by the following steps:

  1. Use the steps described in the secure text field class to create a secure text field.

  2. Select the secure text field.

  3. Option-drag a resize handle of the secure text field. As you drag, Interface Builder creates a matrix containing multiple text field cells.

  4. Clicking once selects the matrix; double-clicking selects a text field cell within the matrix. For each cell:

    1. select the cell

    2. open the Info window and use the pop-up menu to display the Custom Class pane

    3. change the class of the cell to NSSecureTextFieldCell

Properties of secure text field cell objects

In addition to the properties it inherits from the text field cell class, a secure text field cell object has these properties:

echos bullets
 Access:read/write
 Class:boolean
 Should the characters be echoed as bullets? default is true; if set to false, shows blank characters


Elements of secure text field cell objects

A secure text field cell object can contain only the elements it inherits from text field cell.

Examples

The following script statement changes the echos bullets property of a secure text field cell. By default, text characters are displayed as bullets. When bullets are turned off, characters are displayed as blanks.

set echos bullets of cell of secure text field 1 of window 1 to  false
slider
Plural: sliders
Inherits from: control
Cocoa Class: NSSlider

Displays a range of values and has an indicator, or knob, which indicates the current setting.

A slider can optionally have tick marks at regularly spaced intervals. The user moves the knob along the slider's bar to change the setting.

The slider automatically determines whether it's horizontal or vertical by its size. If the slider is wider than it is tall, it's horizontal. Otherwise, it's vertical. A vertical slider has its minimum on the bottom; a horizontal slider has its minimum on the left.

You will find the several kinds of slider objects on the Cocoa-Controls pane of Interface Builder’s Palette window. You can set many attributes for sliders in Interface Builder’s Info window.

Figure 4-12 shows vertical and horizontal sliders with different kinds of knobs, and with and without tick marks. You will find these types of sliders on the Cocoa-Controls pane in Interface Builder’s Palette window.


Figure 4-12  Horizontal, vertical, and circular sliders, with and without tick marks

Horizontal, vertical, and circular sliders, with and without tick marks

For more information, see the document Slider Programming Topics for Cocoa.

Properties of slider objects

In addition to the properties it inherits from the control class, a slider object has these properties:

alternate increment value
 Access:read/write
 Class:real
 the alternate increment value is the amount the slider will change its value when the user drags the knob with the Option key held down (or Alt key on some keyboards)
image
 Access:read/write
 Class:image
 the image for the slider; setting a slider’s image in Cocoa is deprecated, so you shouldn’t set the image in a script either
knob thickness
 Access:read/write
 Class:real
 the thickness of the knob
maximum value
 Access:read/write
 Class:real
 the maximum value of the slider; default is 100.0; you can set this property in the Info window in Interface Builder
minimum value
 Access:read/write
 Class:real
 the minimum vale of the slider; default is 0.0; you can set this property in the Info window in Interface Builder
number of tick marks
 Access:read/write
 Class:integer
 the number of tick marks for the slider; you can set this property in the Info window in Interface Builder; some sliders have no tick marks; for others, the default number is 11
only tick mark values
 Access:read/write
 Class:boolean
 Should only values be allowed that correspond to the tick marks? you can set this property in the Info window in Interface Builder; for sliders that have no tick marks, the default value is false; for sliders with tick marks, the default value is true
tick mark position
 Access:read/write
 Class:enumerated constant from Tick Mark Position
 the position of the tick marks (above or below a horizontal slider, to the left or right of a vertical slider); you can set this property in the Info window in Interface Builder
title
 Access:read/write
 Class:Unicode text
 the title of the slider; setting a slider’s title in Cocoa is deprecated, so you shouldn’t set the title in a script either
title cell
 Access:read/write
 Class:text field cell
 the cell of the title; as with the title property, you should not use this property in your scripts
title color
 Access:read/write
 Class:RGB color
 the color of the title; as with the title property, you should not use this property in your scripts
title font
 Access:read/write
 Class:font
 the font of the title; as with the title property, you should not use this property in your scripts
vertical
 Access:read/write
 Class:boolean
 Is the slider vertically oriented? you can choose vertical or horizontal sliders in Interface Builder


Elements of slider objects

A slider object can contain only the elements it inherits from control.

Events supported by slider objects

A slider object supports handlers that can respond to the following events:

Action
action

Drag and Drop
conclude drop
drag
drag entered
drag exited
drag updated
drop
prepare drop

Key
keyboard down
keyboard up

Mouse
mouse down
mouse dragged
mouse entered
mouse exited
mouse up
right mouse down
right mouse dragged
right mouse up
scroll wheel

Nib
awake from nib

View
bounds changed

Examples

When you add a slider object to a window in Interface Builder, you can set various attributes of the slider, such as its minimum, maximum, and current (or start) values, and its number of markers (or tick marks). The following action handler is from the Language Translator application distributed with AppleScript Studio. For that application, the slider is set to allow a range of 0.0 to 7.0, which corresponds to the volume level range you can set with the set volume scripting addition (where 0.0 is silent and 7.0 is full volume).

This action handler, which is called whenever a user changes the slider setting, gets the slider from the window of the passed theObject parameter. It then gets a volume value based on the current slider setting and calls the set volume scripting addition to adjust the volume at which translated text will be spoken.

on action theObject
    set enabled of slider of window "Language Translator"  to true
    set volumevalue to contents of slider "volumeslider"
        of window "Language Translator" as integer
    set volume volumevalue
end action
Version Notes

Support for drag-and-drop commands was added in AppleScript Studio version 1.2.

stepper
Plural: steppers
Inherits from: control
Cocoa Class: NSStepper

A control consisting of two small arrows that can increment and decrement a value that appears beside it, such as a date or time.

Figure 4-13 shows a stepper to the right of a text field to display the stepper's value.


Figure 4-13  A stepper

A stepper

You will find the stepper object on the Cocoa-Controls pane in Interface Builder’s Palette window. You can set many attributes for steppers in Interface Builder’s Info window.

For more information, see the document Steppers.

Properties of stepper objects

In addition to the properties it inherits from the control class, a stepper object has these properties:

auto repeat
 Access:read/write
 Class:boolean
 Should the stepper auto repeat when clicked? default is true; you can set this property in the Info window in Interface Builder
increment value
 Access:read/write
 Class:real
 the amount to increment the stepper by; default is 1.0; you can set this property in the Info window in Interface Builder
maximum value
 Access:read/write
 Class:real
 the maximum value of the stepper; default is 59.0; you can set this property in the Info window in Interface Builder
minimum value
 Access:read/write
 Class:real
 the minimum value of the stepper; default is 0.0; you can set this property in the Info window in Interface Builder
value wraps
 Access:read/write
 Class:boolean
 Does the value of the stepper wrap? if true, then when incrementing or decrementing, the value will wrap around to the minimum or maximum value; if false, the value will stay pinned at the minimum or maximum; default is true; you can set this property in the Info window in Interface Builder


Elements of stepper objects

A stepper object can contain only the elements it inherits from control.

Events supported by stepper objects

A stepper object supports handlers that can respond to the following events:

Action
clicked

Drag and Drop
conclude drop
drag
drag entered
drag exited
drag updated
drop
prepare drop

Key
keyboard down
keyboard up

Mouse
mouse down
mouse dragged
mouse entered
mouse exited
mouse up
right mouse down
right mouse dragged
right mouse up
scroll wheel

Nib
awake from nib

View
bounds changed

Examples

When you add a stepper object to a window in Interface Builder, you can set various attributes of the stepper, such as its minimum, maximum, current (or start), and increment amount values. The following clicked handler is from the Drawer application distributed with AppleScript Studio. For that application, the stepper that controls leading offset for the drawer is set to allow a range of 0.0 to 1000.0, with an increment amount of 1.0.

This clicked handler, which is called whenever a user clicks the stepper, checks the passed theObject parameter to determine which object it was called for. If it was the leading offset stepper, it gets a leading value based on the current stepper setting and sets the leading offset property of the drawer object. Finally, it sets the value displayed in its associated text field (note that it doesn’t have to convert the value to a string to set the contents of the text field).

on clicked theObject
    tell window "main"
        if theObject is equal to button "drawer" then
    ...
        else if theObject is equal to stepper "leading offset"  then
            set theValue to (contents of stepper "leading offset")
                as integer
            set leading offset of drawer "drawer" to theValue
            set contents of text field "leading offset"  to theValue
    ...

The following script statements, from the action handler of the Drawer application, show how to set the value of the stepper from a value entered in its associated text field.

on action theObject
    set textValue to contents of theObject
    ...
    if theObject is equal to text field "leading offset"  then
        set leading offset of drawer "drawer" to textValue
        set contents of stepper "leading offset" to textValue
...

To set a stepper’s value, and to display the same value in an accompanying text field, you can use statements like the following:

tell window "main"
    set contents of stepper "stepperName" to myNumber
    set contents of text field "textFieldName" to myNumber
end tell

To get the value, use a statement like the following, which returns a real number:

tell window "main"
    set currentStepperValue to contents of stepper "stepperName"
end tell
Version Notes

Support for drag-and-drop commands was added in AppleScript Studio version 1.2.

text field
Plural: text fields
Inherits from: control
Cocoa Class: NSTextField

Provides the ability to input, display, and edit text, as well as to display non-editable text that can be used for labels.

You will find the text field object on the Cocoa-Text pane in Interface Builder’s Palette window. You can set many attributes for text fields in Interface Builder’s Info window. For information on setting font, color, and other attributes for a text field, see the Examples section for the font class.

You can connect an action handler to a text field object in Interface Builder to gain control when a user finishes editing (either by tabbing to another field or by pressing the Enter key). In Interface Builder, you can also optionally set the text field to only call its action handler when the Enter key is pressed (and not when a user tabs out of the field).

AppleScript Studio applications automatically support tabbing between any text fields you add to a window. By default, tab order goes from left to right and down across the window, and is independent of the order in which you insert the text fields. See “Enabling Tabbing Between Objects” in Interface Builder help for a description of how to set tab order between text fields and other objects; you can specify the first object to receive keyboard events (or initial first responder), and each successive object in the responder chain.

Figure 4-14 shows a text field label (“System Font Text”) and an input text field. For more information, see the document Text Fields.


Figure 4-14  Text fields used as labels and input fields

Text fields used as labels and input fields

Properties of text field objects

In addition to the properties it inherits from the control class, a text field object has these properties:

allows editing text attributes
 Access:read/write
 Class:boolean
 Can the user edit the font attributes of the text field? default is false
background color
 Access:read/write
 Class:RGB color
 the background color of the text field; a three-item integer list that contains the values for each component of the color; by default, {65535, 65535, 65535}, or white; you can set this property in the Info window in Interface Builder; for example, red can be represented as {65535,0,0}
bezeled
 Access:read/write
 Class:boolean
 Is the text field bezeled? default is true
bordered
 Access:read/write
 Class:boolean
 Is the text field bordered? default is true; you can set this property in the Info window in Interface Builder
draws background
 Access:read/write
 Class:boolean
 Should the text field draw its background color behind the text? default is true; you can set this property in the Info window in Interface Builder, though you will first have to set the border type to no border
editable
 Access:read/write
 Class:boolean
 Is the text field editable? default is true; you can set this property in the Info window in Interface Builder
imports graphics
 Access:read/write
 Class:boolean
 Should the text field support dropping dragged images? default is false
next text
 Access:read/write
 Class:text field
 not supported (through AppleScript Studio version 1.4); use of the method in Cocoa’s NSMatrix class that this property is based on is no longer encouraged, so this property is not likely to ever be supported; the next text editor
previous text
 Access:read/write
 Class:text field
 not supported (through AppleScript Studio version 1.4); use of the method in Cocoa’s NSMatrix class that this property is based on is no longer encouraged, so this property is not likely to ever be supported; the previous text editor
selectable
 Access:read/write
 Class:boolean
 Can the contents of the text field be selected? default is true; you can set this property in the Info window in Interface Builder
text color
 Access:read/write
 Class:RGB color
 the color of the text; a three-item integer list that contains the values for each component of the color; for example, red can be represented as {65535,0,0}; by default, {0, 0, 0}, or black; you can set this property in the Info window in Interface Builder; see the Examples section for this class for a script statement that sets the text color of a text field


Elements of text field objects

A text field object can contain only the elements it inherits from control.

Events supported by text field objects

A text field object supports handlers that can respond to the following events:

Action
action

Drag and Drop
conclude drop
drag
drag entered
drag exited
drag updated
drop
prepare drop

Editing
begin editing
changed
end editing
should begin editing
should end editing

Key
keyboard up

Mouse
mouse entered
mouse exited
scroll wheel

Nib
awake from nib

View
bounds changed

Examples

Many of the sample applications distributed with AppleScript Studio show how to work with text fields. For example, the Currency Converter application (available starting with AppleScript Studio version 1.1) uses the following statement to get text from a text field. In this statement, the text is stored in the variable theRate, while "rate" specifies the AppleScript name for the text field. (You supply the AppleScript name in the Name field on the AppleScript pane of the Info window in Interface Builder.)

set theRate to contents of text field "rate"

The same application uses the following statement to set the text in another text field to show the result of the currency conversion:

set contents of text field "total" to theRate * theAmount

Note that the text field automatically displays the result as text.

You can use a statement like the following to set the color of text in a text field to red:

set the text color of text field "text1" of window 1 to  {65535, 0, 0}
Version Notes

Support for drag-and-drop commands was added in AppleScript Studio version 1.2. See the “Terminology” for details. In particular, the description for the conclude drop event handler provides information on supporting drag and drop for text view and text field objects.

The next text and previous text properties in this class are not supported, through AppleScript Studio version 1.4. Support for these properties is not likely to be added.

text field cell
Plural: text field cells
Inherits from: cell
Cocoa Class: NSTextFieldCell

Adds to text-display capabilities of a cell object by providing ability to set the color of both the text and its background, as well as to specify whether the cell draws its background at all.

For related information, see cell, as well as the document Text Fields.

You can create and access a text field cell in Interface Builder by the following steps:

  1. Drag a text field from the Cocoa-Text pane of the Palette window to the target window.

  2. Select the text field.

  3. Option-drag a resize handle of the text field. As you drag, Interface Builder creates a matrix containing multiple text field cells.

  4. Clicking once selects the matrix; double-clicking selects a text field cell within the matrix.

Properties of text field cell objects

In addition to the properties it inherits from the cell class, a text field cell object has these properties:

background color
 Access:read/write
 Class:RGB color
 the background color of the cell; a three-item integer list that contains the values for each component of the color; for example, red can be represented as {65535,0,0}; by default, {65535, 65535, 65535}, or white; you can set this property in the Info window in Interface Builder
draws background
 Access:read/write
 Class:boolean
 Should the cell draw its background? you can set this property in the Info window in Interface Builder, though you will first have to set the border type to no border
text color
 Access:read/write
 Class:RGB color
 the color of the text; a three-item integer list that contains the values for each component of the color; by default, {0, 0, 0}, or black; you can set this property in the Info window in Interface Builder


Events supported by text field cell objects

A text field cell object supports handlers that can respond to the following events:

Action
clicked

Nib
awake from nib

Examples

You don’t typically script a text field cell. You can script similar properties (background color, draws background, text color) of a text field instead. However, if you do need to access the properties of a text field cell, you can do so with statements like the following:

set textFieldCell to cell 1 of matrix 1
set myColor to background color of textFieldCell
set draws background of textFieldCell to true

Commands

Objects based on classes in the Control View 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.

animate

Advances the progress animation of an indeterminate progress indicator by one step.

Syntax
animate reference required
Parameters
reference

a reference to the progress indicator to animate

Examples

Given a window “main” with a progress indicator “barber pole” the following statement causes the progress indicator to advance by one step. To animate the progress bar continually, you can either use this statement repeatedly in a loop, or use start.

tell progress indicator "barber pole" of window "main"  to animate

The following statement is equivalent:

animate progress indicator "barber pole" of window "main"
go

Jumps to the specified location in a movie (the direct object).

For related information, see the movie view class.

Syntax
go reference required
 to enumerated constant optional
Parameters
reference

a reference to the movie in which the jump takes place

to  enumerated constant from Go To

the place in the movie to jump to

Examples

The following choose menu item handler is from the Talking Head sample application, available at <Xcode>/Examples/AppleScript Studio. The handler uses the tag value from the chosen menu item in the Movie menu to determine which command to execute.

For the Go to Beginning menu item, the handler uses the go to command to jump to the beginning frame. You can set the tag value for a menu item in Interface Builder in the Attributes pane of the Info window. The tag values in this example are from the Talking Head application.

on choose menu item theMenuItem
    tell window "main"
        set theCommand to tag of theMenuItem
        if theCommand is equal to 1001 then
    ...
        else if theCommand is equal to 1006 then
            tell movie view "movie" to go to beginning  frame
    ...
highlight

Not supported (through AppleScript Studio version 1.4).

Do not use this command.

Syntax
highlight reference required
Parameters
reference

a reference to the object to highlight

increment

Increments the specified object by the specified amount, or by one if no amount is specified.

Syntax
increment reference required
 by real optional
Parameters
reference

a reference to the object to increment

by  real

the amount to increment by

Examples

The following script statements are from the incrementPanel handler of the Mail Search sample application, available at <Xcode>/Examples/AppleScript Studio. This handler is one of several handlers that are part of a script object defined in the Mail Search application to control the status panel window.

    ...
        tell window "status"
            tell progress indicator "progress" to increment  by 1
            ...
            end tell
    ...

These script statements target a determinate progress indicator in a window and use the increment by command to increment the progress indicator.

Version Notes

Prior to AppleScript Studio version 1.1, the Mail Search sample application was named Watson.

pause

Not supported (through AppleScript Studio version 1.4). Pauses the current activity.

Syntax
pause reference required
Parameters
reference

a reference to the object to pause

perform action

Tells the receiving object to perform its action (causes a handler to be executed).

For example, you can tell an interface object, such as a button, to perform its clicked handler, thus providing a way to directly script the user interface. Note, however, that calling the clicked handler will not provide the visual feedback a user would see if they actually clicked the button. For other limitations on scripting the user interface, see AppleScript Studio Programming Guide.

Syntax
perform action reference required
Parameters
reference

a reference to the object that should perform its action

Examples

You can use the following script statements in Script Editor to cause the “Drawer” button in the Drawer application (an AppleScript Studio sample application) to perform its clicked handler, which will either open or close the drawer, depending on its current state. Similar statements will work within an AppleScript Studio application script (though you won’t need the tell application statement).

tell application "Drawer"
    set theButton to button "Drawer" of window "main"
    tell theButton to perform action
end tell
Discussion

The perform action command typically does nothing unless the specified object has an action handler—a handler such as a clicked or double-clicked handler in the Action group in the Interface Builder Info window for the object. You can, however, use the perform action command with menu items, using syntax such as the following:

tell menu item 1 of menu 1 of main menu to perform action
play

Plays the object.

The play command is supported by the movie view class.

Syntax
play reference required
Parameters
reference

a reference to the movie to play

Examples

You can tell a a movie view to play with statements like the following:

tell window "main"
    tell movie view "movie" to play

For a complete example of working with movies, see the Talking Head application, available at <Xcode>/Examples/AppleScript Studio.

resume

Not supported (through AppleScript Studio version 1.4). Resumes the previous activity.

Syntax
resume reference required
Parameters
reference

a reference to the object that should resume its previous activity

scroll

Scrolls the specified object.

Not supported (through AppleScript Studio version 1.4). However, see the Examples section below for information about how to scroll text in a text view.

Syntax
scroll reference required
 item at index integer optional
 to enumerated constant optional
Parameters
reference

a reference to the object that should be scrolled

item at index  integer

the index of the item to scroll to

to  enumerated constant from Scroll To Location

the location to scroll to

Examples

Although the scroll command is not supported through AppleScript Studio version 1.4, you can use the call method command to scroll. For a text view, for example, you can use call method with the scrollRangeToVisible: method of the NSText class (the text view class inherits from text, as NSTextView inherits from NSText).

For a simple window “main” with a text view “myText”, in a scroll view “scroller”, the following statements will scroll to the bottom of the text view.

tell text view "myText" of scroll view "scroller"  of window "main"
    set theText to contents
    set theLength to (length of theText)
    call method "scrollRangeToVisible:" of object it
            with parameter {theLength, theLength}
end tell

Substituting the following version of the call method statement would instead scroll to the top of the view:

    call method "scrollRangeToVisible:" of object it with  parameter {0, 0}
start

Starts an object.

Various classes support the start command. For example, you can use it to start the animation of an indeterminate progress indicator, which causes the barber pole to start spinning. The start command does nothing for a determinate progress indicator.

You can also use the start command to play a movie in a movie view.

Syntax
start reference required
Parameters
reference

a reference to the object to start

Examples

Given a window “main” with an indeterminate progress indicator “barber pole” the following statement causes the progress indicator to start its animation.

tell progress indicator "barber pole" of window "main"  to start

The following statement is equivalent:

start progress indicator "barber pole" of window "main"
step back

Repositions the movie's play position to one frame before the current frame.

If the movie is playing, it will stop at the new frame.

Syntax
step back reference required
Parameters
reference

a reference to the movie view object that receives the step back command

Examples

You can tell a a movie view to step back with statements like the following:

tell window "main"
    tell movie view "movie" to step back

For a complete example of working with movies, see the Talking Head application, available at <Xcode>/Examples/AppleScript Studio.

step forward

Repositions the movie's play position to one frame after the current frame.

If the movie is playing, it will stop at the new frame.

Syntax
step forward reference required
Parameters
reference

a reference to the movie view object that receives the step forward command

Examples

You can tell a a movie view to step forward with statements like the following:

tell window "main"
    tell movie view "movie" to step forward

For a complete example of working with movies, see the Talking Head application, available at <Xcode>/Examples/AppleScript Studio.

stop

Stops an object.

Various classes support the stop command. For example, you can use it to stop the animation of an indeterminate progress indicator, which causes the barber pole to stop spinning. The stop command does nothing for a determinate progress indicator.

You can also use the stop command to stop playing a movie in a movie view.

Syntax
stop reference required
Parameters
reference

a reference to the progress indicator

Examples

Given a window “main” with an indeterminate progress indicator “barber pole” the following statement causes the progress indicator to stop its animation.

tell progress indicator "barber pole" of window "main"  to stop

You can tell a a movie view to stop with statements like the following:

tell window "main"
    tell movie view "movie" to stop

For a complete example of working with movies, see the Talking Head application, available at <Xcode>/Examples/AppleScript Studio.

synchronize

Saves to disk any modifications that have been made to user defaults and updates any unmodified values to what is on disk.

Not supported (through AppleScript Studio version 1.4), but see Examples section for a workaround.

Syntax
synchronize reference required
Parameters
reference

a reference to the user-defaults that should be synchronized

Result
boolean

Returns false if it could not save data to disk; true otherwise.

Examples

You can use the call method command to call synchronize, as follows. These calls return false if the data could not be saved to disk and true otherwise.

-- Works in Mac OS X version 10.2 as well as in earlier versions:
set succeeded to call method "synchronize" of object user  defaults
 
-- Works in Mac OS X version 10.2 and later
set succeeded to call method "synchronize" of user defaults

Events

Objects based on classes in the Control View 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.

action

Called when an action occurs for the object.

This handler gets its name from the Cocoa concept of an action—a method that can be triggered by user interface objects. In AppleScript Studio, action handlers include action, clicked, and double clicked.

The action event handler itself is supported by classes such as combo box, popup button, secure text field, slider, stepper, text field, and text field cell. For example, the action handler for a text field is typically is triggered when a user attempts to tab out of the field or presses the Return key. (You can set a Send Action radio for a text field in the Attributes pane of the Info window in Interface builder.)

You can use the perform action command to cause an action event handler to be called.

Syntax
action reference required
Parameters
reference

a reference to the object that received the action

Examples

The following action handler is from the file Application.applescript in the Unit Converter sample application distributed with AppleScript Studio. This handler just checks whether the object for which the handler was called is a particular text field. If so, it calls another handler to perform the unit conversion (such as converting a value from yards to meters).

on action theObject
    if theObject is equal to text field "Value" of box  1 of window "Main" then
        my convert()
    end if
end action
begin editing

Called before editing begins.

You typically use this handler with a text field, text view, or related object. The handler cannot cancel the editing operation, but can prepare for it.

For example, when a user first presses a key to enter a character into a text field, AppleScript Studio calls the should begin editing handler (if one is installed), which can refuse to allow editing. Then, if editing is allowed, the begin editing handler (if installed). The character is not entered into the field until the application returns from the begin editing handler.

Continuing with this example, AppleScript Studio calls the changed handler (if installed) after the character is entered. When the user presses the Tab key or otherwise attempts to complete editing in that field, AppleScript Studio calls the should end editing handler, which can refuse to allow editing to end (if, for example, the field contains an invalid entry). Then, if editing is allowed to end, AppleScript Studio calls the end editing handler (if installed), where the application can perform any preparation for editing to be completed.

Syntax
begin editing reference required
Parameters
reference

a reference to the text field, text view, or related object for which editing will begin

Examples

When you connect a begin editing handler to an object in Interface Builder, AppleScript Studio supplies an empty handler template like the following. You can use the handler to prepare for editing.

on begin editing theObject
    (* Perform operations here before editing. *)
end begin editing
changed

Called after the contents of an object change.

Typically used to indicate editing has caused a change in the text in a text field, text view, or related object. It is too late to do validation when this handler is called—use should end editing instead. See also begin editing, should begin editing, and end editing.

Syntax
changed reference required
Parameters
reference

a reference to object in which editing caused a change

Examples

When you connect a changed handler to an object in Interface Builder, AppleScript Studio supplies an empty handler template like the following. You can use the handler to respond to any changes due to editing.

on changed theObject
    (* Perform operations here after object changed due to editing.  *)
end changed
clicked

Called when a user clicks the object.

Nearly all subclasses of control support the clicked handler.

Syntax
clicked reference required
Parameters
reference

a reference to the object that was clicked

Examples

The following clicked handler is for the “Convert” button in the Currency Converter application distributed with AppleScript Studio. Currency Converter provides text fields for entering an amount and a conversion rate, a field for displaying the result, as well as the “Convert” button for initiating the conversion.

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

Only one object (the “Convert” button) in the Currency Converter application supports the clicked handler, so in that handler the application knows the theObject parameter is a reference to the button. The handler gets the window of that object so it can access text fields in the same window.

double clicked

Called when a user double-clicks the object.

Subclasses of control such as outline view and table view support the double clicked handler.

Syntax
double clicked reference required
Parameters
reference

a reference to the object that was double-clicked

Examples

The following double clicked handler is for the “messages” table view in the Mail Search application distributed with AppleScript Studio. The table view displays email messages that were found in a search. Double-clicking a selected message should result in opening the message in a document window.

on double clicked theObject
    set theController to controllerForWindow(window of theObject)
    if theController is not equal to null then
        tell theController to openMessages()
    end if
end double clicked

This handler uses the theObject parameter to get the window of the table object so it can access the controller for that window. The controller is responsible for carrying out operations for the window. If the handler can successfully get the controller, it calls the openMessages handler of the controller to actually open the selected message (or messages).

Version Notes

Prior to AppleScript Studio version 1.1, the Mail Search sample application was named Watson.

end editing

Called before editing ends.

You typically use this handler with a text field, text view, or related object. The handler cannot cancel the end of editing, but can prepare for it.

For additional information, see begin editing.

Syntax
end editing reference required
Parameters
reference

a reference to the text field, text view, or related object for which editing will end

Examples

When you connect a end editing handler to an object in Interface Builder, AppleScript Studio supplies an empty handler template like the following. You can use the handler to prepare for editing ending.

on end editing theObject
    (* Perform operations here before editing stops. *)
end end editing
selection changed

Called after the selection of an object changes.

The handler can perform actions in response to the selection change. It is supported by classes such as combo box, outline view, and table view. For example, when a user clicks to select a new row in an outline view, the selection changed handler is called (if one is connected).

Syntax
selection changed reference required
Parameters
reference

a reference to the object whose selection changed handler is called

Examples

The following selection changed handler is from the file Application.applescript in the Task List sample application distributed with AppleScript Studio (starting with version 1.2). This event handler is called whenever the selection in a table view changes. If there are any currently selected rows, this handler calls the setUIValuesWithTaskValues handler to update the user interface based on the selected row. If no row is selected (selection changed to no selection), the handler calls the setDefaultUIValues handler to update the user interface to its default values.

on selection changed theObject
    if name of theObject is "tasks" then
        -- If there is a selection then we'll update the UI;
        --  otherwise we set the UI to default values
        if (count of selected rows of theObject) > 0 then
            -- Get the selected data row of the table view
            set theTask to selected data row of theObject
 
            -- Update the UI using the selected task
            setUIValuesWithTaskValues(window of theObject, theTask)
        else
            -- Set the UI to default values
            setDefaultUIValues(window of theObject)
        end if
    end if
end selection changed
selection changing

Called repeatedly during a drag select operation (such as dragging to select multiple rows in a table or outline view) as items are added or removed from the selection.

The handler can perform actions in response to the changing selection, though it should not perform lengthy operations. When the user concludes the selection (by releasing the mouse), the selection changed handler is called (if one is connected).

Syntax
selection changing reference required
Parameters
reference

a reference to the object whose selection changing handler is called

Examples

When you connect a selection changing handler to an object in Interface Builder, AppleScript Studio supplies an empty handler template like the following. The theObject parameter refers to the object, such as a browser, outline view, or table view, for which selection is changing. You can use the handler to perform actions in response to the changing selection.

on selection changing theObject
    -- Perform operations here in response to changing selection.
end selection changing
should begin editing

Called before editing starts.

The handler can return false to cancel editing. Classes such as text field and text view support this handler.

See also begin editing and should end editing.

Syntax
should begin editing reference required
 object anything optional
Parameters
reference

a reference to the object whose should begin editing handler is called

object  anything

the text view that will do the editing

Result
boolean

Return true to allow editing to begin; false to prevent editing

Examples

The following example of a should begin editing handler calls an application handler isItemEditable, written by you, to determine whether to allow editing to begin, then returns the appropriate value. You might instead perform some kind of test in the handler itself or check some global property.

on should begin editing theObject
    --Check property, perform test, or call handler to see if OK  to edit
    set allowEditing to isItemEditable(theObject)
    return allowEditing
end should begin editing
should end editing

Called before editing ends.

The handler can return false to cancel ending. Classes such as text field and text view support this handler. A common use is to not allow editing to end if the current text is invalid.

See also end editing and should begin editing.

Syntax
should end editing reference required
 object anything optional
Parameters
reference

a reference to the object whose should end editing handler is called

object  anything

the text view that is doing the editing

Result
boolean

Return true to allow editing to end; false to continue editing

Examples

The following example of a should end editing handler calls an application handler isItemValid, written by you, to determine whether to allow editing to end (if the edited item is valid), then returns the appropriate value. You might instead perform validation in the handler itself or check some global property.

on should end editing theObject
    --Check property, perform test, or call handler to see if OK
    --to stop editing (if edited item is valid)
    set allowStopEditing to isItemValid(theObject)
    return allowStopEditing
end should end editing
will dismiss

Called before the object is dismissed.

This command is supported by combo box objects. The handler cannot cancel dismissing, but can prepare for it.

Syntax
will dismiss reference required
Parameters
reference

a reference to the combo box object whose will dismiss handler is called

Examples

When you connect a will dismiss handler to a combo box object in Interface Builder, AppleScript Studio supplies an empty handler template like the following. You can use the handler to prepare for being dismissed.

on will dismiss theObject
    (* Perform any operations to prepare for being dismissed. *)
end will dismiss
will pop up

Called before a pop-up menu pops up.

This command is supported by combo box and popup button objects. The handler cannot cancel popping up, but can prepare for it.

Syntax
will pop up reference required
Parameters
reference

a reference to the combo box or popup button object whose will pop up handler is called

Examples

When you connect a will pop up handler to a combo box object in Interface Builder, AppleScript Studio supplies an empty handler template like the following. The theObject parameter refers to the combo box or popup button that is about to pop up. You can use the handler to prepare for popping up (such as checking the items in the combo box or popup button).

on will pop up theObject
    (* Perform any operations to prepare for popping up. *)
end will pop up


< Previous PageNext Page > Hide TOC


© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-10-31)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.