Hi, Byron.
If an AppleScript list has been written to file, as in Trash Man’s script, “LIST” and “TEXT” are there in the file along with some other stuff as part of the stored list structure. In ‘read the_file as list’, the ‘as list’ is a parameter (not a coercion) that tells ‘read’ to interpret the data as a list. If instead you use ‘read the_file as text’, or just ‘read the_file’, the ‘read’ command assumes that the file just contains text and interprets the data as such “ and you see things you’re not meant to see.
So: if you have a file containing list data, and you want to coerce the list to text, you have to read it first as a list and then coerce the list to text:
set read_data to (read the_file as list) as text
Note that:
- The first ‘as’, not separated from ‘read’ by parentheses, is a labelled parameter of ‘read’. The second ‘as’ is an AppleScript coercion.
- This won’t work with Trash Man’s list as it contains records, which can’t be coerced to string.
- Incidentally, ‘path to’ too has an optional ‘as’ parameter, whose use is slightly more efficient than an AppleScript coercion:
((path to desktop) as string) -- 'path to' returns an alias, which AppleScript then coerces to string.
(path to desktop as string) -- 'path to' returns a string directly.
-- However, the received wisdom nowadays is to use Unicode text for paths:
(path to desktop as Unicode text) -- 'path to' returns Unicode text directly.