Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Apple > Operating Systems

  • Print
  • + Share This
From the author of Writing the Code

Writing the Code

Click the AppDelegate.applescript file in the Project Navigator to display the main AppleScript code of the project. The default AppleScriptObjC template contains some code, including applicationWillFinishLaunching and applicationShouldTerminate handlers (methods), as shown in Figure 12. We won't use these handlers for this project.

Figure 12 The default AppDelegate.applescript code.

Above the applicationWillFinishLaunching handler, add the following property and handler:

property textField : missing value

on buttonClicked_(sender)
      display alert "Hello there " & (stringValue() of textField)
end buttonClicked_

Notice that the textField property is set to a missing value. This tells AppleScriptObjC that the property serves as an interface outlet. In other words, once we finish wiring it up, it provides a way for the AppleScript code to interact directly with the interface's text field.

buttonClicked is a custom handler. Once it's linked to the interface, it's triggered when the user clicks the button in the main window. This handler calls the stringValue Objective-C method of the text field to retrieve the field's value.

Figure 13 shows how the completed script should look.

Figure 13 The customized AppDelegate.applescript file.

  • + Share This
  • 🔖 Save To Your Account