Scripting Additions Guide

CHAPTER 2
Scripting Addition Commands
52 Command Definitions
You can use the as className parameter to specify how the Read command
should interpret the data it reads. If data to be read is not a valid value for the
specified value class, the Read command returns an error. The rest of this
section describes some of the value classes you can specify and the nature of
the data returned if the Read command reads the data successfully.
as list The Read command returns a list only if the data to be read was
written to disk as an AppleScript list. If the data to be read is
delimited text, you can specify the delimiters used in the data
with the using delimiter parameter, and the Read
command creates an AppleScript list based on those delimiters.
For example, this script returns a list of items from MyFile using
both tab and return characters in MyFile to separate each item in
the list:
read file "Hard Disk:MyFile" as {text} ¬
using delimiters {return, tab}
The resulting list, like any other AppleScript list, is comma-
delimited. You can’t specify more than two delimiters; if you do,
Read returns the error –50.
as record Read returns a record only if the data being read was written to
disk as an AppleScript record. Read can’t coerce other values
to records.
as integer If the data consists of a single integer, Read returns the integer. If
the data consists of more than one integer, Read returns a list
of integers.
as text Read returns the data as a string. This is the default behavior if
the as className parameter is omitted.
as real If the data consists of a single real number, Read returns the real
number. If the data consists of more than one real number, Read
returns a list of real numbers.
as short The short value is defined by the Read/Write Commands
scripting addition as 2 bytes long. This can be is useful if you are
reading data from a file that uses short integers rather than the
4-byte integers defined by AppleScript. Read interprets the data
as one or more discrete 2-byte values. If the data consists of