home *** CD-ROM | disk | FTP | other *** search
/ AppleScript - The Beta Release / AppleScript - The Beta Release.iso / Example Scripts / Example Scripts (as text) / Syntax Examples
Encoding:
Text File  |  1992-12-02  |  2.1 KB  |  94 lines  |  [TEXT/ToyS]

  1. (* Syntax Sampler *)
  2. -- talking to an application
  3. tell application "Toy Surprise"
  4.     commandLine
  5. end tell -- or just plain "end"
  6.  
  7. -- Conditionals
  8. if expr then
  9.     commandLine
  10. else if expr then
  11.     commandLine
  12. else
  13.     commandLine
  14. end if
  15.  
  16. -- Iteration
  17. repeat n times
  18. end repeat
  19.  
  20. repeat with i in {v1, v2}
  21. end repeat
  22.  
  23. repeat with i from 1 to 100 by 10
  24. end repeat
  25.  
  26. repeat while expr
  27. end repeat
  28.  
  29. repeat until expr
  30. end repeat
  31.  
  32. repeat
  33.     if expr then exit
  34. end repeat
  35.  
  36. -- Error handling
  37. on error
  38.     commandLine
  39. end error
  40.  
  41. -- Functions/Subroutines
  42. on FunctionName(param, param2)
  43.     local a, b, c
  44.     global x, y, z
  45.     commandLine
  46.     return expr
  47. end FunctionName
  48.  
  49. to userFunction of x
  50.     return userFunction of expr
  51. end userFunction
  52.  
  53. actor "Redfern"
  54.     property propName : expr
  55.     on Message()
  56.         commandLine
  57.     end Message
  58. end actor
  59.  
  60. -- assignment
  61. copy expr to expr
  62. set variable to object -- links var to object
  63.  
  64. -- special messages
  65. class count in obj
  66. make class at obj with data expr with properties recordOfProperties
  67.  
  68. (* Expressions.   Operators with the same precedence are presented in lists *)
  69. {before obj, after obj, in front of obj, in back of obj, behind obj}
  70. {expr whose testExpr, expr where testExpr}
  71. {beginning, front, end}
  72. {expr or expr}
  73. {exrp and expr}
  74. {not expr}
  75. {expr is equal to expr, expr = expr, expr isn't equal to expr}
  76. {object is PropertyTrue, object is not PropertyTrue}
  77. {expr comes before expr, expr comes after expr, expr < expr, expr = expr, expr ≥ expr}
  78. {expr starts with expr, expr begins with expr, expr ends with expr, expr contains expr, expr is contained by expr}
  79. {StringOrList & StringOrList} -- concatenation
  80. {expr of expr, item i in list} -- element access
  81. {class ID expr, class named expr, class expr}
  82. {expr + expr, expr - expr}
  83. {expr * expr, expr div expr, expr mod expr, expr ÷ expr}
  84. {expr ^ expr} -- power
  85. {expr as class} -- type conversion
  86. {my PropertyOrClass, its PropertyOrClass}
  87. {every class, some class, first class, last class, middle class}
  88.  
  89. (* Values *)
  90. {item1, item2} -- lists
  91. {label1:value1, label2:value2} --records
  92. {userFunction of expr, userFunction(expr1, expr2, expr3)}
  93. {class index, 1st class, 2nd class, 3rd class, fourth class, fifth class, 6th class, pi, space, return, tab}
  94.