• 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: Steve Mills <email@hidden>
  • Date: Mon, 29 Sep 2003 15:48:57 -0500

On Monday, Sep 29, 2003, at 14:52 US/Central, Randy Beaudreault wrote:

I'm having problems with the next portion of my script. I'm unable to write to my file:
set Date_File to open for access file ":Users:maccult:Library:Preferences:once-a-day" with write permission
write (day of (current date)) to Date_File
close access Date_File

I'm wondering if my syntax is correct or is this a bug with the Standard Additions?

The file access commands have always been problematic. One thing you need to do is always call the commands from the same target. Like if you do this:

tell app "Finder"
set refNum to (open for access "disk:file" with write permission)
end tell

tell app "TextEdit"
write "blah" to refNum
end tell

It won't work, because the open file's reference number belongs to Finder, not TextEdit.

As for writing to existing files, that's also a huge problem. What I've found works best in most cases is to make sure the file doesn't already exist before opening it for write by deleting it either with the Finder or Unix. I think it's OS9 that still thinks the file is around if you simply tell the Finder to delete it, or I could be thinking of trying to open a file a 2nd time after the script had errored while it had it open before. In any case, most of the scripts I write these days will only run in OSX, so I use Unix to delete files:

do shell script "rm " & quoted form of posix path of "disk:file"

Also, depending on what format you want your date file in, you might want to coerce the data to a string first, since I think "day of" will return an enum:

write (day of (current date)) as string to Date_File

Steve Mills
Drummer, Mac geek
http://sjmills5.home.mchsi.com/
_______________________________________________
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: Richard Morton <email@hidden>
References: 
 >Writing To A File (From: Randy Beaudreault <email@hidden>)

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