• 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: sending data from one AppleScript App to another
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sending data from one AppleScript App to another


  • Subject: Re: sending data from one AppleScript App to another
  • From: Paul Berkowitz <email@hidden>
  • Date: Fri, 05 Sep 2003 11:00:39 -0700

On 9/5/03 1:14 AM, "Michael Glasser" <email@hidden> wrote:


> This sounds like it is getting close to my needs.
>
> Here is a full list of my needs:
> 1) AIM Script has to create / write to the file -- you covered this
> 2) Bot Script has to read from the file -- you covered this (well, can
> I read just the first few lines?)

Yes. You can 'read for ' so many bytes, if you kept track of how many.
Simpler is just to read the whole thing and then get paragraphs 1 thru 4, or
whatever:

set r to read theFile
set theFirstLines to paragraphs 1 thru 4 of r
set AppleScript's text item delimiters to {return}
set pp to theFirstLines as string
set AppleScript's text item delimiters to {""}

> 3) Bot Script has to erase ONLY what it has read. This may be just the
> 1st 4 lines of a 400 line (or longer) file -- any ideas?

In the script above:

set r to read theFile
set theFirstLines to paragraphs 1 thru 4 of r
set AppleScript's text item delimiters to {return}
set pp to theFirstLines as string
set AppleScript's text item delimiters to {""}

> 3) Bot Script has to erase ONLY what it has read. This may be just the
> 1st 4 lines of a 400 line (or longer) file -- any ideas?

In the script above:

set f to open for access theFile with write permission
set r to read f
set theFirstLines to paragraphs 1 thru 4 of r
set theRest to paragraphs 5 thru -1 of r
set AppleScript's text item delimiters to {return}
set pp to theFirstLines as string
set theRest to theRest as string
set AppleScript's text item delimiters to {""}
set eof f to 0 -- wipes it clean
write theRest to f
close access f
>
> I *can* have the Bot Script read the whole file and then write back
> what needs to be written back, but wouldn't that slow things down?

Only if you can't afford 1/100th of a second or so. That's about all it
takes. This is _Fast_.
> What happens if the AIM Script is writing to it at the same time?

Only one access can have write permission at a time. You'd get a "busy"
error. So put it in a try block, like this:

set done to false
repeat until done
try
set f to open for access theFile with write permission
set done to true
on error
delay 1
end try
end repeat
-- rest of the script above
>
> Also, is there a quick way to know the number of lines the file has.

In the script above, insert one line after

set r to read f
set c to (count paragraphs of r)
>

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

References: 
 >Re: sending data from one AppleScript App to another (From: Michael Glasser <email@hidden>)

  • Prev by Date: Re: Searching for a folder in Applescript.
  • Next by Date: Re: Microsoft Word 5.1 versus Word for Office X
  • Previous by thread: Re: sending data from one AppleScript App to another
  • Next by thread: Remove Final C/R?
  • Index(es):
    • Date
    • Thread