• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: read write basics
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: read write basics


  • Subject: Re: read write basics
  • From: Paul Skinner <email@hidden>
  • Date: Thu, 05 Jul 2001 15:56:40 -0400

on 7/5/01 11:45 AM, Marc K. Myers wrote:

>> Date: Thu, 05 Jul 2001 05:24:59 -0400
>> Subject: read write basics
>> From: monk <email@hidden>
>> To: "applescript users (apple)" <email@hidden>
>>
>> hi list
>>
>> at a loss as to how to write a text file, just trying to get my i/o
>> framework going on a newbie script i'm throwing together
>>
>> here's what i have so far, and i always end up with an 'execution error'
>> that the file i'm trying to write "wasn't found"
>>
>> i expect there is some command that i need prior to writing the file, and
>> when i try 'create file . . . ' i get a 'syntax error' 'expected end of
>> line, etc. but found class name' (so it's a bad command i suppose), anyway:
>>
>> copy (choose file) to _source
>>
>> read _source as list using delimiter space
>>
>> write result to file "myhd:desktop folder:new source"
>
> Try this:
>
> set _source to (choose file)
> set fileID to (open for access _source)
> set theText to (read _source as text)
> close access fileID
> set fileID to (open for access file "myhd:desktop folder:new source" ,
> with write permission)
> set eof fileID to 0
> write theText to fileID starting at eof
> close access fileID
>
> List I/O doesn't work, at least I've never gotten it to work. It's
> better to convert your lists to delimited text on output and convert
> them back to lists on input. If your output is tab-delimited, you can
> turn it back into a list this way:
SNIP
This is fixed in AS 1.6. Reading and writing lists works properly.

set listData to {1, 2, 3, 4, 5, "a", "b", "c", "d", "e"}
set datafile to "dark star:Desktop Folder:datafile"
try
close access file datafile
--prevents the possibility of trying to open an open file.
end try
set dataFileRef to (open for access file datafile with write permission)
write listData to dataFileRef
close access dataFileRef

set readData to read file datafile as list
-->{1, 2, 3, 4, 5, "a", "b", "c", "d", "e"}

--
"AppleScript is digital duct tape."
Paul Skinner


  • Follow-Ups:
    • Re: read write basics
      • From: monk <email@hidden>
References: 
 >Re: read write basics (From: "Marc K. Myers" <email@hidden>)

  • Prev by Date: Re: read write basics
  • Next by Date: Re: GREP in Akua's "the entries in"
  • Previous by thread: Re: read write basics
  • Next by thread: Re: read write basics
  • Index(es):
    • Date
    • Thread