Name

read

Synopsis

read data

read data

Reads data from a file, optionally treating it as a specified datatype (for an example, see "Forming Unicode Text" in Chapter 13); the default is string (not Unicode text). There are options for where to start (character position values start at 1), how many characters to read, and where to stop. The using delimiter parameter is poorly documented: this is a list of one-character strings, any of which will be used to break the data into a single-level list of strings (which will lack all the delimiter characters). The until and before parameters fail when reading as string if they are out of the basic ASCII range (over 128), but they work using Unicode text.

Example

set f to (path to desktop as string) & "someUTF16file.txt"
set ff to open for access file f
set d1 to read ff as Unicode text
d1 -- "Mannie¬Moe¬Jack"
-- testingdelimiter parameter
set notsign to "¬" as Unicode text
set L to read ff from 1 as Unicode text using delimiter notsign
L -- {"Mannie", "Moe", "Jack"}
-- testingbefore parameter
set d2 to read ff from 1 as Unicode text before notsign
close access ff
d2 -- "Mannie"

Get AppleScript: The Definitive Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.