# System messages

## Commands sent automatically

HyperCard sends some commands automatically in response to events, just as it sends system messages. But unlike system messages, if the command passes all the way to HyperCard, HyperCard performs a built-in action. So if you trap the command, the action won't happen.

HyperCard sends choose and `doMenu` as messages when the user chooses a tool or an item from one of HyperCard’s menus. It sends close as a message when the user clicks the close box of a window.

HyperCard sends help as a message when the user chooses Help from the Go menu (or presses Command-?).

HyperCard sends `arrowKey`, `commandKeyDown`, `controlKey`, `enterInField`, `enterKey`, `functionKey`, `keyDown`, `returnInField`, `returnKey`, and `tabKey` as messages when the user presses a key.  It automatically sends `errorDialog` and `appleEvent` messages.

Click Related Topics for more information about each command.

## Message sending orders

For some events, HyperCard automatically sends a sequence of system messages.

For example, when you close an existing stack by opening another one, HyperCard sends the following system messages in order: `closeCard`, `closeBackground`, `closeStack`, `openStack`, `openBackground`, `openCard`.

Click an event to see the order in which HyperCard sends multiple system messages in response to it.

HyperCard startup
Resume
New stack
New stack in a new window
New background
New card
Delete stack
Delete background
Delete card
Cut card
Paste card

## Where messages are sent initially

HyperCard automatically sends system messages and a few commands to one of three objects: a specific button, a specific field, or the current card. If none of these objects handles the message, it continues along the message- passing order until it reaches HyperCard itself.

The commands HyperCard sends automatically deal with keyboard events and menu events. Click an object to see the messages it can receive from HyperCard.

Buttons
Fields
The current card

## appleEvent

```
appleEvent <class>, <id>, <sender>
```

Handler:

```
on appleEvent class, id, sender
   <statements>
end appleEvent
```

HyperCard sends the appleEvent message to the current card when it receives an Apple event from another program. It sends the message at idle time as soon as all pending handlers have finished running.

*class* is the general category of the event (such as `aevt` or `misc`), *id* is the actual event received (such as `odoc`, `pdoc`, `dosc`, or `eval`), and *sender* is the name of the application or process that sent the event.

Because Apple event commands are usually generated by other processes, you may want to check to make sure that they are not destructive. Click Examples to see a handler, written for the Home stack, that intercepts an incoming Apple event.

You'll see lots of `appleEvent` messages in the message watcher when HyperCard is being controlled by AppleScript from another application.

Apple events generated internally when HyperCard runs AppleScript don’t produce `appleEvent` messages.

Use the `request` command within an `appleEvent` handler to obtain additional information about the event.

You don't have to define an appleEvent handler to enable HyperCard to handle Apple events. Use an `appleEvent` handler only if you need to get a peek at the incoming Apple events or to handle them yourself.

The `appleEvent` message occurs only under System version 7.0 and later.

## closeBackground

```
closeBackground
```

Handler:

```
on closeBackground
   <statements>
end closeBackground
```

HyperCard sends the `closeBackground` message to the current card when a user (or handler) quits HyperCard, goes to a card whose background is different from the background of the current card, and when a background or stack is deleted.

## closeCard

```
closeCard
```

Handler:

```
on closeCard
   <statements>
end closeCard
```

HyperCard sends the `closeCard` message to a card when a user (or script) goes to another card; deletes a card, background, or stack; or quits HyperCard.

## closeField

```
closeField
```

Handler:

```
on closeField
   <statements>
end closeField
```

HyperCard sends the `closeField` message to an unlocked field when, after editing, a user (or handler) performs an action that closes (that is, removes the insertion point from) the field. HyperCard sends `closeField` only when the text actually changes.

The following actions close a field, saving any changes that were made to the text:

* Clicking outside the field
* Moving the insertion point   to the next field with the Tab key
* Pressing the Enter key
* Pressing Command-Shift-Z to revert   the field to the last saved version
* Going to another card
* Quitting HyperCard

## closeStack

```
closeStack
```

Handler:

```
on closeStack
   statements
end closeStack
```

HyperCard sends the `closeStack` message to the current card when a user (or script) opens a different stack in the current window, closes the current window, deletes the stack, suspends HyperCard to launch an application, or quits HyperCard.

Note: If you have more than one stack open at a time, HyperCard sends `suspendStack`, not `closeStack`, when the stack becomes inactive.

## deleteBackground

```
deleteBackground
```

Handler:

```
on deleteBackground
   <statements>
end deleteBackground
```

HyperCard sends the `deleteBackground` message to the card that is being deleted if no other cards in the stack share its background. HyperCard sends the message just before the card disappears.

Note: You cannot stop a background from being deleted by trapping the `deleteBackground` message. Instead, you must handle the `doMenu` message or set the `cantDelete` property for the background.

## deleteButton

```
deleteButton
```

Handler:

```
on deleteButton
   <statements>
end deleteButton
```

HyperCard sends the `deleteButton` message to a button that is being deleted just before the button disappears.

Note:  You cannot stop a button from being deleted by trapping the `deleteButton` message. Instead, you must handle the `doMenu` message.

## deleteCard

```
deleteCard
```

Handler:

```
on deleteCard
   <statements>
end deleteCard
```

HyperCard sends the `deleteCard` message to a card that is being deleted just before the card disappears.

## deleteField

```
deleteField
```

Handler:

```
on deleteField
   statements
end deleteField
```

HyperCard sends the `deleteField` message to a field that is being deleted just before the field disappears.
