(no subject)
(no subject)
- Subject: (no subject)
- From: Oakley Masten <email@hidden>
- Date: Wed, 31 Mar 2010 08:03:53 -0700 (PDT)
On Tue, 30 Mar 2010 Dave Wrote
From: red_menace <email@hidden>
Subject: Re: Read/Write Text Files
>I agree that using a text file for preferences isn't really the way to go.
>The following is an example that writes and then reads a data record from a file:
>-- 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
>- Dave
Thanks DaveThis is going to take a bit of time for me to digest but I appreciate your sharing it.
Oakley
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden