Subject: | |
From: | |
Reply To: | |
Date: | Thu, 22 May 2003 00:23:01 +0900 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
Hello Eric,
On Wednesday, May 21, 2003, at 11:18 PM, Eric Schult wrote:
>
> I like Tanaka's for its ability to readFromFile in one line of code,
> without
> having to open for access and close access (and having to worry about
> leaving
> the file busy if there's an error before the close access line is
> reached).
> It's just a quibble, really; it's what I'm used to.
Yes, I understand you. AppleScript's "open for access", "close access"
are really cumbersome.
>
> The same argument for writeToFile in Tanaka's. It's just cleaner. AND
> I'm
> admittedly fretting the thousands of lines of code I'm going to have
> to edit
> in the absence of Tanaka's. Oh, well. I guess Open for Access it is.
>
> I kinda hoped somebody would chime in with the prospects of doing the
> same
> thing with command line scripting. I'm no UNIX geek or anything, but
> what
> little I've heard suggests a write to file command can be accomplished
> in the
> terminal. I just don't know the syntax. Is it truth or fiction that
> command
> line scripts like that offer exponentially better performance?
>
I don't know at all about performance issue, but it seems that shell
scripts for reading from/writing to files are much easier than
AppleScript. You would write something like:
echo 'abcedfg' > ~/mydoc.txt
to write "abcdefg" to the text file "mydoc.txt" in
/User/[your_account]/ folder.
And you would write:
cat ~/mydoc.txt
to read the contents of your "mydoc.txt" file.
In AppleScript, that would be:
do shell script "echo " & quoted form of your_text & " > " & quoted
form of (POSIX path of your_file_path)
and
do shell script "cat " & quoted form of (POSIX path of your_file_path)
=====
I may probably use these three sub-routines:
on write_to_file(str, fpath)
do shell script "echo " & quoted form of str & " > " & quoted form of
(POSIX path of fpath)
end write_to_file
on append_to_file(str, fpath)
do shell script "echo " & quoted form of str & " >> " & quoted form of
(POSIX path of fpath)
end append_to_file
on read_from_file(fpath)
return do shell script "cat " & quoted form of (POSIX path of fpath)
end read_from_file
Please try them...
Best regards,
Nobumi Iyanaga
Tokyo,
Japan
|
|
|