Scripting Additions Guide
Table Of Contents
CHAPTER 2
Scripting Addition Commands
78 Using Read/Write Commands
try
(* first put the record to be added into a variable; in this case
the record to be added is actually an AppleScript list because
the file on disk doesn’t include label data *)
set newRecord to ¬
{"Granny", "Smith", "123 Potato Chip Lane", ¬
"Palo Minnow", "CA", "98761", "Snackable Computer", ¬
"888-987-0987", "978 -234-5432", "123-985-1122"}
set x to open for access pathToUse with write permission
AddRecord(newRecord, 5, tab, return, x)
close access x
on error errString number errNum
display dialog errString
close access x
end try
on AddRecord(recordToAdd, addWhere, fieldDelimiter, ¬
recordDelimiter, fileRefNum)
try
--initialize variables
set idx to 1 --counter
set preRecordSize to 1 --offset of byte at which to add file
set accumulatedSize to 0 --total size of records read
set numberOfFields to count of recordToAdd
if recordDelimiter is "" then
set readxTimes to numberOfFields
else
set readxTimes to numberOfFields - 1
end if
(* if the record is to be added at the beginning of the file,
this If statement adds the record *)
if addWhere is 1 then
--read from beginning of file and store in postBuffer