Hello!
I have made an AppleScript that generates a text-file (actually a Markdown file).
However, every time I run this script the (new) text is appended to the existing text.
I would like to make sure at the beginning of the script that the Markdown-file is empty, and if not, I would like to delete the existing content.
How to do this in AppleScript?
Thanks in advance!
Kind regards,
Vlad Ghitulescu
Model: iMac 3.06 GHz Inte Core 2 Duo
AppleScript: 2.2.1
Browser: Safari 534.53.10
Operating System: Mac OS X (10.7)
StefanK
February 29, 2012, 7:30pm
#2
Hallo Vlad,
it depends on the way to write into the file.
For example using AppleScript’s read/write capabilities it’s sufficient to set the eof pointer to zero.
Gruss nach Essen
set eof
set eof (verb) Set the length, in bytes, of a file (from the File Read/Write suite, defined in StandardAdditions.osax)
command syntax
set eof any ¬
to integer
direct parameter required any a file reference number, alias, or file reference of a file
to required integer the new length of the file, in bytes. Any data beyond this position is lost.
Examples
If you want to completely replace the contents of an existing file, the first step must be to change its length
to zero:
set theFile to choose file with prompt “Choose a file to clobber:”
set eof theFile to 0
CHAPTER7
Commands Reference
Thanks a lot, mouramartins, it works and I have learned again something new
Regards,
Vlad
Thanks, Stefan!
I’ve just wanted to ask HOW to set the eof pointer to zero… but mouramartins was faster!
Gruß zurück,
Vlad