
- AppleScript Resources
- Function Calls
- Closure
Apple is one of the best resources for AppleScript documentation. Here's some files you might want to check out:
- AppleScript Language Guide (880 K) - Indepth description of AppleScript's syntax.
- Scripting Additions Guide (340 K) - Everything you ever wanted to know about Scripting Additions-- how to use them, and even make them.
- AS Guide to Scriptable Apps (630 K)- An out of date list of all AppleScriptable apps.
- Language at a glance (70 K) - HyperCard stack. It is the best reference I know of for quickly finding a short overview of any part of AppleScript's syntax! Get it!
- Using AppleScript (50 K) - Really short documentation on how to use Script Editor.
Non-Apple files:
- Danny Goodman's AppleScript Quick Reference (80 K) - Drop this AppleGuide into the same folder as your Script Editor and enjoy. It's a little more descriptive than Apple's "Language at a glance" and supports copy/paste of examples inside AppleGuide. However, since it's an AppleGuide it can be sluggish.
Internet resources:
- ScriptWeb - MacOS scripting resource. You can find almost anything you need from this site.
- www.scripting.com - Userland Software's web site. The makers of "Frontier".
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.)
- -- A simple handler
- on foo (x)
- return x ÷ 2
- end foo
- -- calling syntax:
- foo (3)
- -- => 1.5
- -- more examples
- on getEnd from stringIn at searchString
- global aString
- local x, y, z
- -- some statements
- end getEnd
- -- calling syntax:
- getEnd from "a string" at "str"
- on insertString into stringIn at searchString given insertString:insertText
- -- some statements
- end insertString
- set myString to "this is a line of text"
- -- calling syntax:
- insertString into myString at "line" given insertString:"*BIG* "
- -- you can use the "with" and "without" to pass in boolean data
- on getdata from fileName given fastRead:booleanflag1, recordLock:booleanflag2, message:msgString
- return {booleanflag1, booleanflag2, msgString}
- end getdata
- -- calling syntax:
- getdata from "hd:file" with fastRead without recordLock given message:"hi"
- -- ==> {true, false, "hi"}
- -- calling syntax:
- getdata from "hd:file2" without fastRead and recordLock given message:"cool!"
- -- ==> {false, false, "cool!"}
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