Skip to content

Activate an Event Handler

This is really basic, and explained in most tutorials for AppleScript Studio out there, but since I haven’t explained it very eloquently, here is what I mean when I say in various postings that one must activate an event handler before one adds some code.

When you want to write some code for a button press, a menu selection, respond to a keyboard event, etc. in Interface Builder you must explicitly lay out your intentions by activating the event handler in question. For example, if you want to do something in response to the user pressing a key in a text field (see next posting), then:

1. Click on the text field in Interface Builder.
2. Open the AppleScript tab of the inspector.
3. It is good practice to give your object a name here, which can be used to refer to the object in your script.
4. Choose your applescript that you want to attach to this object in the “Script” pop-up menu here.
5. Activate the check mark next to “keyboard up” in the “Key” section of the “Event Handlers” pane.

Interface BuilderScreenSnapz001.jpg

Forgetting to give an object a name, forgetting to assign it to a script and activate the correct event handler are common mistakes I have made that prevented me from getting any results.

A handy shortcut: You can directly jump to the empty method created by activating the handler by double-clicking the relevant handler.