Re: Simple question.... writing to file
Re: Simple question.... writing to file
- Subject: Re: Simple question.... writing to file
- From: Simon Topliss <email@hidden>
- Date: Thu, 10 Feb 2005 12:38:48 +0000
On 10 Feb 2005, at 12:26 pm, Christian Vinaa wrote:
uhhhhh writing to file......
i sure wish there were some basic scripts awailable that worked for
sure and then I could build on them
write to file has always been a big problem for me :-((
I've been using the following set of handlers for a while now...
set dataToWrite to {1, 2, 3, 4, 5}
set logFilePath to (path to desktop folder as string) & "Test.txt"
writeToFile(logFilePath, dataToWrite)
--appendToFile(logFilePath, dataToWrite)
on writeToFile(logFilePath, dataToWrite)
set theStr to listToStr(dataToWrite)
closeAccess(logFilePath)
try
set fileRef to open for access file logFilePath with write permission
set eof fileRef to 0
write theStr to fileRef
closeAccess(fileRef)
on error m number n
closeAccess(fileRef)
error m number n
end try
end writeToFile
on appendToFile(logFilePath, dataToWrite)
set theStr to listToStr(dataToWrite)
closeAccess(logFilePath)
try
set fileRef to open for access file logFilePath with write permission
write theStr to fileRef starting at ((get eof fileRef) + 1)
closeAccess(fileRef)
on error m number n
closeAccess(fileRef)
error m number n
end try
end appendToFile
on listToStr(dataToWrite)
if class of dataToWrite is list then
set {oldDelims, AppleScript's text item delimiters} to {AppleScript's
text item delimiters, {return}}
set theStr to dataToWrite as string
set AppleScript's text item delimiters to oldDelims
return (theStr & return)
else
return dataToWrite as string
end if
end listToStr
on closeAccess(fileRef)
try
close access fileRef
end try
end closeAccess
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden