-- set up the file name and data record
set theFile to (choose file name default name "AppleScript Test Data")
set theData to {theDate:date "Monday, April 5, 2010 12:00:00 AM", thePath:((path to desktop) & "Example.txt") as text, theColors:{"red", "blue", "green"}, theNumbers:{22, 71, -18, -35, 6}}
-- write the data to the file
do shell script "touch " & quoted form of POSIX path of theFile -- make sure it is there
try
set theOpenFile to open for access theFile with write permission
set eof of theOpenFile to 0 -- overwrite
write theData to theOpenFile as record
close access theOpenFile
on error errorMessage -- make sure file is closed
log errorMessage
try
close access theOpenFile
end try
end try
-- read the data from the file and set some variables
set x to read theFile as record -- don't need "open for access" if just reading
set myDate to theDate of x
set myFilePath to thePath of x
set myColors to theColors of x
set myIntegers to theNumbers of x
-- show stuff
log x
display dialog third item of myColors --> "green"
display dialog third item of myIntegers --> -18