Read UTF8 file works in Lion but not in Snow Leopard

Part of my script:


set printers to POSIX file "/tmp/printerlist.txt"
open for access printers
set printerlist to (read printers using delimiter "," as «class utf8»)
close access printers

set UI1 to choose from list printerlist

In the file printerlist.txt there are special characters, like åäö. These characters are displayed correctly in Lion, in the “choose dialog” that pops up. But when I run the script in Snow Leopard, these characters are not displayed correctly.
Can anyone please explain why?

Hi, psychozz. Welcome to MacScripter.

The ‘using delimiter’ parameter was only designed to work with plain (8-bit) text, so possibly it’s forcing the file data to be interpreted as such. The best course is just to read the data as «class utf8» and then use AppleScript’s text item delimiters to break up what you get:


set printers to POSIX file "/tmp/printerlist.txt"
set printerlist to (read printers as «class utf8»)

set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
set printerlist to printerlist's text items
set AppleScript's text item delimiters to astid

set UI1 to choose from list printerlist

Thanks! Works perfect :slight_smile: