Re: Writing To A File
Re: Writing To A File
- Subject: Re: Writing To A File
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 30 Sep 2003 09:32:18 -0700
On 9/30/03 6:20 AM, "Steve Mills" <email@hidden> wrote:
>
Yes, I know it's a standard addition. I was illustrating what not to
>
do. As for how bulletproof these commands are, I disagree. Run this
>
twice:
>
>
tell application "Finder"
>
set rn to open for access "Gort:Users:sjmills:Desktop:testblah" with
>
write permission
>
write "bob" to rn
>
close access rn
>
end tell
>
>
One the 2nd run, I get "Finder got an error: Duplicate file name. some
>
object". Take out the Finder targeting and I get "Duplicate file name.
>
Gort:Users:sjmills:Desktop:testblah".
>
>
Now add the class "file" before the pathname and it works. Clearly,
>
it's a bug that it doesn't work a 2nd time if you pass a pathname
>
string. THIS is the problem I always have, and it's not obvious that I
>
have to remember to type "file" in front of it, because almost every
>
other app or command I regularly use that takes a file reference works
>
no matter what when I pass a pathname string instead of a file or
>
alias. If other apps and commands are written to be smart enough to
>
always accept a string, then these commands should be too.
Look, Steve. The Standard Additions Dictionary says:
open for access file -- the file or alias to open for access. If the file
does not exist, a new file is created.
See that "file"? It's required. It's not optional. It's not a bug that you
have to write 'file' or 'alias' (which is coerced to 'file' when it exists
already). It's part of the command. If you don't like that, too bad. It's
not negotiable.
So why can you skip 'file' the first time? In my opinion, that's a sort of
bug, but hardly a serious one It must be one of those Finder coercions,
supposed to make things easier for you, imperfectly executed here. Beginners
often like these coercions but they lead to false expectations IMO. (And I'd
agree that at least they should be consistent within the app.) So that may
be a Finder bug - not unusual. But it's not a bug in the 'open for access'
command. All you have to do is follow the syntax in the dictionary, and you
won't have any problems. That's no bug. Just use correct syntax and don't
skip 'file' or 'alias'. (In fact, in AppleScript generally, outside of
whatever particular applications might choose to do, there are only two
place where you can skip 'file' or 'alias' before path names, and that's
'list folder' which was a 3rd-party osax once upon a time, so I guess they
kept it for backwards compatibility. And 'save', which saves a lot of
problems when applications have their own 'file' term.)
--
Paul Berkowitz
_______________________________________________
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.