Resolved AppleScript: How to blank a text file?

Discussion in 'Mac Programming' started by WhoGotTheChunk, Jan 1, 2012.

  1. WhoGotTheChunk, Jan 1, 2012
    Last edited: Jan 4, 2012

    WhoGotTheChunk
    Expand Collapse
    macrumors newbie

    Joined:
    Feb 5, 2010
    #1
    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
     
  2. Red Menace
    Expand Collapse
    macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2
    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.
     
  3. WhoGotTheChunk
    Expand Collapse
    thread starter macrumors newbie

    Joined:
    Feb 5, 2010
    #3
    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.
     
  4. subsonix
    Expand Collapse
    macrumors 68040

    Joined:
    Feb 2, 2008
    #4
    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).
     
  5. WhoGotTheChunk
    Expand Collapse
    thread starter macrumors newbie

    Joined:
    Feb 5, 2010
    #5
    Found a site on how to do it.

    used the command

    Code:
    set eof contactsFile to 0
     
  6. ratsg
    Expand Collapse
    macrumors 6502

    Joined:
    Dec 6, 2010

Share This Page