Scripting Additions Guide
Table Of Contents
CHAPTER 2
Scripting Addition Commands
Command Definitions 51
The next example reads MyFile starting at the end of the file and reading
backward until the third byte from the end.
read file "Hard Disk:MyFile" from -1 to -3
If the last characters of file MyFile were "123456", the preceding example would
return "654".
NOTES
The file mark is a marker used by the File Manager that indicates the byte at
which the Read command expects to begin reading data. By default, the file
mark is the first byte of the file. However, running a script like this causes the
file mark for MyFile to be moved:
read file "Hard Disk:MyFile" from 1 to 4
The file mark for MyFile is now at byte 5, so the next Read command in the
same script begins at byte 5. For example, the command
read file "Hard Disk:MyFile" for 4
reads bytes 5 through 8.
To specify the name (nameString) of a file, use a string of the form
"Disk:Folder1:Folder2:...:Filename" as described in Chapter 5, “Objects and
References,” of the AppleScript Language Guide. If you specify only the name of
the file (Filename) instead of its entire pathname, AppleScript attempts to find
the file in the current directory.
If you specify a reference to a file or an alias, the Read command attempts to
match the reference with a file previously opened with the Open for Access
command. If a match is found, it simply reads the specified data. If no match is
found, the Read command opens the file, reads the specified data, then closes
the file. The file mark for a file opened in this fashion is always at the beginning
of the file.
If you specify a file reference number previously obtained with the Open for
Access command, the Read command reads the specified data immediately.