AppleScript返回带有奇怪字符的文本

时间:2012-07-31 08:14:55

标签: text applescript character

我有一个脚本来返回文本文件的一部分,但我注意到它有时会返回直接查看文本文件时不可见的字符。例如,单词:

breeders

变为

breed‰ rs

我尝试添加"作为Unicode文本"我的文字返回,但那不起作用。思考?这是我的剧本:

set some_file to "[...]Words.txt" as alias
set the_text to read some_file as string
set the text item delimiters of AppleScript to ", "
set the_lines to (every text item of the_text)
return some item of the_lines as Unicode text

1 个答案:

答案 0 :(得分:4)

您是否曾尝试使用ruby -KU -e '"breeders".chars{|c|puts c.unpack("U*")[0].to_s(16)}'或搜索字符查看器中未正确显示的字符?

除非您添加read,否则

as «class utf8»会混淆非ASCII字符:

do shell script "echo ä > /tmp/test.txt"
read POSIX file "/tmp/test.txt" as «class utf8»

as textas stringas Unicode text等效since 10.5