• 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: How to add text to the beginning of a file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to add text to the beginning of a file


  • Subject: Re: How to add text to the beginning of a file
  • From: David Nelson <email@hidden>
  • Date: Wed, 22 May 2002 10:18:40 -0500

Hello,

I'm sure someone will correct me if I am wrong, but I think the only way to add something to the beginning of a file is to read the whole file into a variable and then use the concatenation operator to prepend your data then write the data back to the file. Something like this:

set headlineText to ("AppleScript is Way Cool!" & return) -- Headline to prepend to my article.
set fRef to open for access file "Mac HD:article.txt" with write permission
set mainText to read fRef
set modText to (headlineText & mainText) -- Prepend the headline.
set eof of fRef to 0 -- empty the file
write modText to fRef
close access fRef


On Tuesday, May 21, 2002, at 06:39 PM, Kinsella, John R. wrote:
Here's one I can't figure out. I need to add text to a file at the
beginning of a file. (I know how to add it to the end of a file {write
theText to file TheFile starting at eof}
_______________________________________________
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.

  • Follow-Ups:
    • Re: How to add text to the beginning of a file
      • From: Christopher Nebel <email@hidden>
  • Prev by Date: Re: ignoring application completely
  • Next by Date: Re: ignoring application completely
  • Previous by thread: How to add text to the beginning of a file
  • Next by thread: Re: How to add text to the beginning of a file
  • Index(es):
    • Date
    • Thread