• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Extending the Language

Subroutines let you write your own AppleScript commands and use them in AppleScript applications. Subroutines simplify your applications by letting you write your own functions to handle specific events that occur multiple times in your program. By creating a subroutine, you write the commands once, and then just call the subroutine when needed. Subroutines are much like being able to write your own event handlers for special events that occur repeatedly in your program. Initiate calls to user-defined subroutines by specifying the name of the subroutine and the variables that you want to pass to it, enclosed within parentheses and separated by commas as appropriate.

Subroutine definitions are usually located after the main loop of your program and consist of the on keyword followed by a declaration that identifies the name of the subroutine and whatever variables it uses, followed by a set of associated statements that are executed whenever the subroutine is called. Subroutine definitions are terminated with an end statement to differentiate them from any subroutines that follow.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint