Re: open for access error
Re: open for access error
- Subject: Re: open for access error
- From: Nigel Garvey <email@hidden>
- Date: Mon, 11 Feb 2002 13:47:45 +0000
Matt wrote on Sun, 10 Feb 2002 17:45:08 -0500 (EST):
>
I'm trying that, but I need to concatenate a path (folder) to the file to
>
write, so maybe a better question would be:
>
How do I write a file that doesn't exist to a known path and have it be
>
created. I'm thinking the following is the general idea:
>
set theDir to alias (path to desktop as string)
>
set theFile to "newfile.txt"
>
set fref to (open for access (theDir & theFile) with write permission)
>
close fref
>
>
...but it keeps saying it "can not make [it] into an item."
>
Even the basic sample from Nutshell won't work and gives the above error:
>
set fref to (open for access (path to desktop as string) & "test.txt")
>
close fref
There's a hell of a lot of confusion going on here between aliases and
strings. The Nutshell example should read:
set fref to (open for access file ((path to desktop as string) &
"test.txt"))
Note the addition of the word 'file'. (You could use 'alias' instead, if
required.)
You start by getting the path to the desktop as a string. You need it in
string form because you want to concatenate another string ("test.txt")
to it. After the concatenation, you have a string representing the path
to the file on the desktop - but at this stage it's still only a string.
'Open for access' requires a file specification or an alias, so you need
to put the word 'file' or 'alias' in front of the string to show that's
what you mean. (A couple of third-party scripting additions allow
automatic, background coercions from path string to file specification
where this is required - making the use of the word 'file' unnecessary
here. People who have these additions installed sometimes forget why
their scripts actually work!)
In your own script, the first line:
>
set theDir to alias (path to desktop as string)
... gets the path as a string and immediately turns it back to an alias.
(The same result as from 'set theDir to (path to desktop)'.) Leave out
the word 'alias' in that line and use 'file' or 'alias' in the 'open for
access' line instead:
set theDir to (path to desktop as string)
set theFile to "newfile.txt"
set fref to (open for access file (theDir & theFile) with write
permission)
close fref
NG
_______________________________________________
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.