Jump to content

Applescript Blank Out Text File?


JrMasterModelBuilder
 Share

Recommended Posts

JrMasterModelBuilder

I've been trying to make a simple program that will read the clipboard, and write any text it contains to a text file, completely overwriting the previouse data. I achieved this on Windows with some simple C++, but I would like to have the same functionality on a Mac.

Since I couldn't find any way to use GetClipboardData() on a Mac (if there is a way, I would like to hear it [i know there's a pbcopy and pbpaste command in Terminal, but I don't know if I can use that in a C++ program]). I did find that AppleScript can do pretty much what I want, except for one little kink.

Writing a text file and accessing the clipboard is pretty easy and straight-forward with loads of tutorials on the web, but there's one problem with the writing files I can't seem to find a solution to. Say we have an AppleScript write "Hello world!" to a file. That works all well and good, but say we then have the script write "Hi there" to that same file. You will then find "Hi thererld!" in the text file. It only overwrite what the new string is long enough to cover up which makes the script essentially useless. :( So, if anyone knows how to completely blank out a text file before writing to it in AppleScript (or how to have C++ get the clipboard on a Mac), I would love to hear it! I would prefer to avoid deleting the whole text file, then creating a new file each time, but if there is no solution, I guess I'll have go with that.

I've Googled everything I could think of, but no help. :(

EDIT: Never mind, I figured out how to do it. For anyone interested, "set eof of the_file to 0".

Link to comment
Share on other sites

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.