How to delete the content of a text file

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)

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

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 :wink:

Regards,
Vlad

Thanks, Stefan!

I’ve just wanted to ask HOW to set the eof pointer to zero… but mouramartins was faster! :wink:

Gruß zurück,
Vlad