Mac AppleScript: How to blank a text file?

WhoGotTheChunk

macrumors newbie
Original poster
Feb 5, 2010
16
0
I have a text file that I need to blank every time I run a script. At the moment I'm just deleting it and making a new one. I'm sure theres a better way because I get the trash sound every time the script runs.

I think its pretty simple if you have the know how.

Thanks,
Chunk
 
Last edited:

Red Menace

macrumors 6502
May 29, 2011
416
75
Littleton, Colorado, USA
Is this something that your script writes to? You could do something like open the file for write access and set eof to 0 - also, using the rm command in a do shell script won't make any noise.
 

WhoGotTheChunk

macrumors newbie
Original poster
Feb 5, 2010
16
0
Well what I'm doing is storing a list in there of contacts, then when someone connects to the chat system, it updates it and says hello to them. When someone leaves, it removes them from the list. The only way I've found to do it is delete the file otherwise there is text left at the end of the text file.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
In bash (possibly others as well) shell script you can blank a file like this:

Code:
> filename
This does not unlink the file, but set the length to 0 bytes. Beware that you get no warnings or second chances here though (same with rm without -i flag).
 

Similar threads

  • Aouttier
7
Replies
7
Views
601
  • Aouttier
5
Replies
5
Views
467
  • gpchess2k
6
Replies
6
Views
1K
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.