• 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: Simple question.... writing to file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple question.... writing to file


  • Subject: Re: Simple question.... writing to file
  • From: Bernardo Hoehl <email@hidden>
  • Date: Thu, 10 Feb 2005 10:55:20 -0200

Hi List!


I was missing this line from Simon's script:

set eof fileRef to 0

Thanks to you all

Bernardo


=================================

On 10 Feb, 2005, at 10:38 AM, Simon Topliss wrote:

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

 _______________________________________________
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

References: 
 >Simple question.... writing to file (From: Bernardo Hoehl <email@hidden>)
 >Re: Simple question.... writing to file (From: Christian Vinaa <email@hidden>)
 >Re: Simple question.... writing to file (From: Simon Topliss <email@hidden>)

  • Prev by Date: Re: Simple question.... writing to file
  • Next by Date: Creating Links in Entourage Mail
  • Previous by thread: Re: Simple question.... writing to file
  • Next by thread: Re: Simple question.... writing to file
  • Index(es):
    • Date
    • Thread