• 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
Re: Writing To A File
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Writing To A File


  • Subject: Re: Writing To A File
  • From: Paul Skinner <email@hidden>
  • Date: Tue, 30 Sep 2003 11:42:41 -0400

On Tuesday, September 30, 2003, at 09:20 AM, Steve Mills wrote:

On Monday, Sep 29, 2003, at 23:08 US/Central, Richard Morton wrote:

Yep. As Paul B pointed out, 'open for access' has nothing to do with the Finder. These commands are part of the Standard Additions osax.

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.


The dictionary is clear...

write: Write data to a file that was opened for access with write permission (defined in: StandardAdditions.osax)
write anything -- the data to write to the file
[for double integer] -- the number of bytes to write; if not specified, write all the data provided
[starting at double integer] -- start writing at this position in the file
to anything -- the reference number or alias or file reference of the file to write to
[as type class] -- how to write the data: as text, data, list, etc.

'write' doesn't accept paths at all. But silent coercion makes you think that it will. I assume that's done to avoid having to tell the Finder to make a new file and then use Std Additions to read/write it.
Damn user friendly AppleScript strikes again!

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.

Even the Std. Additions ones?

PS
_______________________________________________
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.

  • Follow-Ups:
    • Re: Writing To A File
      • From: Walter Ian Kaye <email@hidden>
    • Re: Writing To A File
      • From: Steve Mills <email@hidden>
References: 
 >Re: Writing To A File (From: Steve Mills <email@hidden>)

  • Prev by Date: Re: Writing To A File
  • Next by Date: Re: Writing To A File
  • Previous by thread: Re: Writing To A File
  • Next by thread: Re: Writing To A File
  • Index(es):
    • Date
    • Thread