• 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: referencing stuff in other files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: referencing stuff in other files


  • Subject: Re: referencing stuff in other files
  • From: Mr Tea <email@hidden>
  • Date: Sat, 25 Feb 2006 16:05:53 +0000

This from Jeremy Matthews - dated 25/2/06 13.59:

> Is there a way you can reference an item/list string, or other errata
> in another file (perhaps, an applescript file?).

What you probably want here is the 'file read/write' commands from the
'standard additions' osax provided with AppleScript.

A simple script for reading the contents of a text file might look like
this:

  set f to "Diskname:Foldername:Filename"
  open for access file f
  set filecontents to read file f
  close access file f

This will store the text of the file in the variable 'filecontents'
(assuming that the path provided in line one points to a valid file).

If you need more complexity, you can also specify which part of a file to
read from/to. The commands are fairly straightforward and I have reproduced
them here for your convenience.

-->>>>>

File Read/Write : Commands for reading and writing information in a file

open for access: Open a disk file for the read and write commands (defined
in: StandardAdditions.osax)
    open for access file  -- the file or alias to open for access.  If the
file does not exist, a new file is created.
         [write permission boolean] -- whether to allow writing to the file.
    Result: small integer  -- a file reference number; use for Œread¹,
Œwrite¹, and Œclose access¹

close access: Close a file that was opened for access (defined in:
StandardAdditions.osax)
    close access anything  -- the file reference number, alias, or file
reference of the file to close

read: Read data from a file that has been opened for access (defined in:
StandardAdditions.osax)
    read anything  -- the file reference number, alias, or file reference of
the file to read
         [from double integer] -- starting from this position; if omitted,
start at last position read from
         [for double integer] -- the number of bytes to read from current
position; if omitted, read until the end of the fileŠ
         [to double integer] -- Šor stop at this positionŠ
         [before string] -- Šor read up to but not including this characterŠ
         [until string] -- Šor read up to and including this character
         [using delimiters list of string] -- Šor a list of values that
separate items to read
         [as type class] -- the form in which to read and return data
    Result: anything  -- the data read from the file

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
         to anything -- the file reference number, alias, or file reference
of the file to write to
         [starting at double integer] -- start writing at this position in
the file
         [for double integer] -- the number of bytes to write; if not
specified, write all the data provided
         [as type class] -- how to write the data: as text, data, list, etc.

get eof: Return the length, in bytes, of a file (defined in:
StandardAdditions.osax)
    get eof anything  -- a file reference number, alias, or file reference
of a file
    Result: double integer  -- the total number of bytes in the file

set eof: Set the length, in bytes, of a file (defined in:
StandardAdditions.osax)
    set eof anything  -- a file reference number, alias, or file reference
of a file
         to double integer -- the new length of the file, in bytes.  Any
data beyond this position is lost.

--<<<<<


Nick
pp Mr Tea

--


 _______________________________________________
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: referencing stuff in other files
      • From: kai <email@hidden>
References: 
 >referencing stuff in other files (From: Jeremy Matthews <email@hidden>)

  • Prev by Date: Re: Deluge of smime 3.p7s
  • Next by Date: Re: list syntax
  • Previous by thread: referencing stuff in other files
  • Next by thread: Re: referencing stuff in other files
  • Index(es):
    • Date
    • Thread