我无法回答你的问题。你的代码中有很多applescript编码问题,但是没有一个会导致你的问题。 Applescript为我处理非ASCII文本。我用丹麦语写了一段时间,它很有用。然而,当我使用俄语尝试我的脚本时,我得到了和你一样的结果。我无法解释为什么。就这样你可以看到读取和写入文件的正确语法,这里是我的代码。请注意,我不使用Finder来执行这些任务,还要注意我是如何设置的路径输出文件...
set outpath to (path to desktop as text) & "danish.txt"
set theText to "primær"
-- write the file
set openFile to open for access file outpath with write permission
write theText to openFile
close access openFile
-- read the file
set readText to read file outpath
更新:我找到了答案,您的问题。看起来,如果您将utf-16字节顺序标记(BOM)写入文件,那么它对于俄文来说可以正常工作。因此,我做了两个处理程序,以便您可以读取和写入这些文件...
set filePath to (path to desktop as text) & "russian.txt"
set theText to "Привет"
write_UnicodeWithBOM(filePath, theText, true)
read_UnicodeWithBOM(filePath)
on write_UnicodeWithBOM(filePath, theText)
try
set openFile to open for access file (filePath as text) with write permission
write (ASCII character 254) & (ASCII character 255) to openFile starting at 0
write theText to openFile starting at eof as Unicode text
end try
try
close access openFile
end try
end write_UnicodeWithBOM
on read_UnicodeWithBOM(filePath)
read file (filePath as text) as Unicode text
end read_UnicodeWithBOM
您打开该文件时用的是什么?听起来像什么显示文件给我的问题。它没有检测到字符集,而是将问号替换为无法显示的字符。 – Brad 2010-12-01 21:53:18