Re: How do I Read and Write a list to a file
Re: How do I Read and Write a list to a file
- Subject: Re: How do I Read and Write a list to a file
- From: John Delacour <email@hidden>
- Date: Wed, 6 Nov 2002 10:48:05 +0000
- Mac-eudora-version: 5.3a8
At 12:12 am -0800 6/11/02, Alan Kimelman wrote:
I have been unable to write a list to a file and read it again as a
list. Instead, the Applescript returns a string.
set t to {"abc", "def"}
tell application "Finder"
set Par to "Macintosh HD:Library:Scripts: My Mail:"
set doc to "New Doc"
set a to (Par & doc)
try
close access alias a
end try
set y to (open for access alias a with write permission)
set eof of y to 0
write t starting at 1 to y as list
set z to read y from 1 to get eof y
close access y
end tell
z returns a string "listTEXTabcTEXTdef" that is meaningless to me.
Please explain the syntax of listTEXT and please explain how I can
retrieve a list.
A list can contain all sorts of types, not only strings, and the text
file created with read/write commands can contain only text, but
provided your list contains only strings, do something like the
script below, using a delimiter which will not occur in your list
items (often 'return').
It will make your life easier if you change the name of your volume
to something short and sweet (mine are called d9, dx, dx2 etc.) and
don't use spaces at the beginning of file names.
set f to "" & (path to scripts folder) & "newdoc.txt"
set ls_ to {"abc", "def"}
set itemseparator_ to {"~"}
set AppleScript's text item delimiters to itemseparator_
set s to "" & ls_ -- change the list to a string
set AppleScript's text item delimiters to {""}
open for access file f with write permission
set eof file f to 0
write s to file f
close access file f
read file f using delimiter itemseparator_
JD
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.