set the_file to "Crocs:Users:oliver:Desktop:Err.txt" as alias
open for access the_file
set the_text to read the_file
close access the_file
return the_textTo write to a text file (by default, at the beginning) you can use:
set the_file to "Crocs:Users:oliver:Desktop:Err.txt" as alias
open for access the_file with write permission
write the_text to the_file
close access the_file
return the_textIf you want to write to the end of the text file use:
write the_text to the_file starting at eof("eof" stands for "end of file".)
Finally, I've written this simple AppleScript subroutine to act as a substitute for the "echo" shell script command:
on write_file(the_file, the_info, overwrite_contents)
try
close access the_file
end try
set opened_file to open for access the_file with write permission
if overwrite_contents is true then set eof of opened_file to 0
write the_info to the_file starting at eof
close access the_file
end write_file
on run
write_file((choose file), (return & "Hello"), false)
end runUsing that, you can specify where to write, what to write, and whether or not to overwrite the original file.
0 comments:
Post a Comment