Subroutines
Making functions and calling them

Table of Contents:

AppleScript Resources
Function Calls
Closure


AppleScript Resources

Apple is one of the best resources for AppleScript documentation. Here's some files you might want to check out:

Non-Apple files:

Internet resources:

 

Function calls

This is the syntax of how to define a subroutine or function:

( on|to ) subroutineName    ¬
      [of | in directParameterVariable]¬
      [subroutineParamLabel paramVariable]¬
 [given label:paramVariable [,label:paramVariable]]
  [global variable [, variable]]
  [local variable [, variable]]
  [statement]
end [subroutineName]

This is the syntax of how to call a subroutine or function defined as the above:

subroutineName [(of | in)directParameter]¬
 [subroutineParamLabel  parameterValue]¬
  | [ with labelForTrueParam [, labelForTrueParam] ¬
      [ ( and | or | , ) labelForTrueParam ] ] ¬
    | [without labelForFalseParam [,labelForFalseParam]¬
     [ ( and | or | , ) labelForFalseParam ] ] ¬
 [given label:parameterValue [,label:parameterValue]]]

This is an alternate syntax of how to define a subroutine or function:

(on | to) subroutineName (paramVariable [,paramVariable])
     [global variable [, variable ]
     [local variable [, variable ]
     [statement]
   end [subroutineName]

This is an alternate syntax of how to call a subroutine or function:

subroutineName (parameterValue [, parameterValue])

Examples: (taken from the "Language at a glance" HyperCard stack.)

 

Closure

Dan Zink made a few other fun Ircle bot scripts relating to Workshop #2. (This text will be moved there after today.) One listens for questions on an IRC channel, and then repeats a random question every 10 seconds. The other translates everything said on a channel to "op" langauge... it is almost like a pig-latin converter.

There is much more to AppleScript than what I have gone over. Hopefully this will be enough of a starter to get you interested in learning more about it.

Some examples of things not yet covered:

«event betamsgA» this is the semi-internal way AppleScript "tokenizes" scripts.
records and fields just sub-variables of "containers".
containers/objects the italicised items at the left when viewing an AppleScript dictionary

 

Go back to the Table Of Contents
 
An AppleScript Tutorial for ACM's MacWarriors group by Steven Bytnar
Copyright 1996, Steven Bytnar