Re: reading a file in an applescript.
Re: reading a file in an applescript.
- Subject: Re: reading a file in an applescript.
- From: Christopher Nebel <email@hidden>
- Date: Fri, 21 Mar 2008 15:25:25 -0700
On Mar 21, 2008, at 12:44 PM, Mark J. Reed wrote:
On Fri, Mar 21, 2008 at 3:35 PM, Doug Meade <email@hidden>
wrote:
Hi folks!
New to applescript ...
I'm trying to read a file in an applescript.
I've tried a number of different syntax options.
The most simple is:
read theTextFile
Well, that won't work...
Not all by itself, to be sure, since "theTextFile" isn't defined, but
if it is, then no problem. For instance, this works:
set theTextFile to choose file of type {"public.text"}
read theTextFile
Here's a model:
set targetFile to (choose file with prompt "Pick a file")
set readHandle to (open for access targetFile)
set fileText to (read readHandle for (get eof readHandle))
close access readHandle
fileText
Everything there other than the "choose file" and the "read" is
superfluous, as the revised ASLG will tell you. "read" and all the
other file commands don't require you to to call "open for access"
first, though you can get certain benefits by doing so, and "read", if
not instructed otherwise, will read the entire file.
That "expected end of line, etc. but found identifier" is a compile
error, which means there's something syntactically invalid somewhere
in the script, so all these recommendations about adding "as alias"
and whatnot aren't going to solve it.
--Chris Nebel
AppleScript Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden