Re: open for access question
Re: open for access question
- Subject: Re: open for access question
- From: Andrew Oliver <email@hidden>
- Date: Fri, 02 May 2003 15:54:14 -0700
It's all to do with object classes, and can be very confusing since it
doesn't always work the way you'd expect, partly because AppleSript tries to
do much of the work for you, but doesn't always go far enough, or do it when
you expect it to.
First thing to note is that the 'open for access' command takes a file
parameter:
This means that you must pass it a file object, or *something that can be
coerced into a file*
In your first case:
open for access ((path to startup disk as Unicode text) & "file.txt")
Fails because "(path to startup disk as Unicode text) & "file.txt")" returns
a unicode text object. AppleScript cannot automatically coerce unicode text
into a file.
instead:
open for access file ((path to startup disk as Unicode text) & "file.txt")
It works... The only change is that you coerce the unicode text to a file
before it's passed to 'open for access', and everything's hunky dorey.
A similar situation occurs in your other example, where you:
set theFile to "startup disk:Folder:Subfolder:Text.txt"
In this case, theFile' is a string/text object. You need to coerce this to a
file before passing it to open for access, so:
open for access file theFile
works where
open for access theFile
doesn't.
In summary, it's a good idea to coerce the objects to the type you want (or,
more specifically, the type the command you're using wants)
Andrew
:)
On 5/2/03 3:24 PM, "Carl Albrecht-Buehler" <email@hidden> wrote:
>
Hi again everyone
>
>
Sorry to bother you with this, but I'm a little confused about how to
>
properly access files. Right now I have the following script:
>
>
set theFIle to (choose file)
>
open for access theFile
>
set fileContents to (read the file from 25 before return)
>
close access theFile
>
>
This works for me, but now I would like to hard code a path name instead of
>
using "choose file". I've tried a number of different iterations in order
>
to try to get a specific file to open with 'open for access' and I always
>
get errors:
>
>
if i open for access ((path to startup disk as Unicode text) &
>
"Folder:Subfolder:Text.txt" I get a Duplicate file name error
>
>
if I set theFile to ((path to startup disk as Unicode text) &
>
"Folder:Subfolder:Text.txt"
>
>
if I set theFile to "startup disk:Folder:Subfolder:Text.txt" I get a 'File
>
wasn't found error with the open for access highlighted.
>
>
Can someone please enlighten me to the correct procedure to get a specific
>
file from a hard code path and then open it for access?
>
>
Thanks,
>
>
Carl
>
_______________________________________________
>
applescript-users mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/applescript-users
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.