• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
open a text file and evaluating in Applescript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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?


  • Follow-Ups:
    • Re: open a text file and evaluating in Applescript
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: Re: Scripting Additions: Embracing the Horror of Unix
  • Next by Date: Re: open a text file and evaluating in Applescript
  • Previous by thread: Re: OS X - Make new Finder window bug
  • Next by thread: Re: open a text file and evaluating in Applescript
  • Index(es):
    • Date
    • Thread