open a text file and evaluating in Applescript
open a text file and evaluating in Applescript
- Subject: open a text file and evaluating in Applescript
- From: email@hidden
- Date: Tue, 29 Jan 2002 22:58:45 EST
I've been surfing through the web for code snippets on how to read a text file in Applescript and display the results. I'm sure this is a simple process, but I'm missing something.
Let's say I have a text file called "text.txt" in a folder called "Experiments" on my Mac OS X drive. I create an applescript and save it as a standalone applicaton, in the exact-same folder, which looks like this:
tell application "Finder"
activate
set file_in_string to "text.txt"
try
set originalfile to open for access file file_in_string
on error error_message number errNum
display dialog "2: " & errNum & " " & error_message
end try
try
read originalfile
copy the result to readstring
display dialog "readstring = " & readstring
on error error_message number errNum
display dialog "3: " & errNum & " " & errr_message
close access orginalfile
end try
end tell
Instead of displaying the readstring variable, I just get an error. End-of file, or subsequently "Duplicate File-name" errors. Can someone else show me how they read a text file into a string and display it in Applescript?