Name

write

Synopsis

write data

write data

Writes data to a file, optionally treating it as a specified datatype; thus you can store any kind of data in a text file and retrieve it later (it will be read correctly if you specify the same class when writing and when reading). There are options for where to start and how much data to write; writing at the end of a file appends, but writing in the middle of the file overwrites existing data (it doesn't insert).

Example

set f to a reference to file ((path to desktop as string) & "justTesting")
open for access f with write permission
write {"Mannie", "Moe", "Jack"} as list to f
close access f
open for access f
set L to read f as list
close access f
L -- {"Mannie", "Moe", "Jack"}

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.