• 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: When is a file open but not open?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: When is a file open but not open?


  • Subject: Re: When is a file open but not open?
  • From: deivy petrescu <email@hidden>
  • Date: Sat, 6 Aug 2005 09:26:47 -0400


On Aug 6, 2005, at 4:56, Emmanuel wrote:

At 5:20 PM -0400 8/5/05, deivy petrescu wrote:

1 - you need sequential access: for instance, you want to write several things one after the other:

write "hello"
write " "
write "world"


I disagree with you here Emmanuel.

When you write you can write wherever you want. You have to let the script know where you want to write to.
So "write to file starting at (you fill this)" works the same way whether opened for access or not.
You can try.



I find it not always easy to "fill this". Tell me how you would store several records without opening the file (both for writing and for reading) like in:


set r to open for access f with write permission
write {name:"deivy"} to r
write {name:"emmanuel"} to r
close access r

set r to open for access f
set x to read f as record
set x to read f as record
close access r

x's name


As per your request:

<script>
set pd to path to desktop as Unicode text
set r to ("" & pd & "testanu.txt") as alias

write {name:"Santos"} to r
write {name:"Santos Campeao"} to r


set x to read r as record

x's name
--> "Santos Campeao"

</script>

2 - you need to be sure that no-one is also writing to the file: open with write permission does lock the file - actually I think it's the OS' genuine mechanism to lock whatever resource might be accessed by several clients.


Here, I really do not know and yield to Emmanuel's knowledge.


I would not do that.

Well, you can afford that, I can not! :)


There are ways around this. You could lock and unlock the file as needed.


Maybe you're right, I don't know to what extent a "locked" file is locked. locking is something you have Finder do? Can you be sure it's synchronous? OMM Finder's "set locked to true/false" cycle is 12 times slower (25 ms) than the "open for access/close access" cycle (2 ms.)


Emmanuel

I've never tried, mostly because I am the only one scripting here, and if necessary "delays" would fix synchronization problems. Now, I was not sure before, but I am now, locked is locked. In classic, you can set a file to ttro ((teach)text read only). An user can not write to it, but AS can. A locked file, it is locked. No one can write to it!
I would actually suggest that read and write should be enclosed by a begin/end transaction. This way, one would make sure that you are the only one writing to a file at that time.
Also, I am not sure that if two different machines are tackling the same file at once, one open for access definitely closes access to the file for the second machine.
I should try this at one point. I've got to get back to business before I do that...


Deivy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: When is a file open but not open?
      • From: Emmanuel <email@hidden>
References: 
 >RE: When is a file open but not open? (From: "Grimm, Kenneth" <email@hidden>)
 >RE: When is a file open but not open? (From: Emmanuel <email@hidden>)
 >Re: When is a file open but not open? (From: deivy petrescu <email@hidden>)
 >Re: When is a file open but not open? (From: Emmanuel <email@hidden>)

  • Prev by Date: Re: When is a file open but not open?
  • Next by Date: Mail and Attachments
  • Previous by thread: Re: When is a file open but not open?
  • Next by thread: Re: When is a file open but not open?
  • Index(es):
    • Date
    • Thread