character encoding - Writing Russian text to txt file -
i trying write russian text, or cyrillic text, .txt file. can so, when open file written in place of text bunch of question marks. thinking encoding problem couldn't find in area help. have written little script demonstrates issue.
do shell script "> $home/desktop/russian\\ text.txt" set text_path ((path home folder) & "desktop:russian text.txt" string) alias set write_text "Привет" tell application "finder" write write_text text_path set read_text text of (read text_path) end tell
if has ideas why happening please let me know. thank you.
i can't answer question. have lots of applescript coding issues in code none of them causing problem. applescript handles non-ascii text fine me. write in danish times , works. when tried script using russian got same results you. can't explain why. can see proper syntax reading , writing file here's code. note not use finder perform tasks , note how set path output file...
set outpath (path desktop text) & "danish.txt" set thetext "primær" -- write file set openfile open access file outpath write permission write thetext openfile close access openfile -- read file set readtext read file outpath
update: found answer problem. seems if write utf-16 byte order mark (bom) file works russian. such made 2 handlers can read , write these files...
set filepath (path desktop text) & "russian.txt" set thetext "Привет" write_unicodewithbom(filepath, thetext, true) read_unicodewithbom(filepath) on write_unicodewithbom(filepath, thetext) try set openfile open access file (filepath text) write permission write (ascii character 254) & (ascii character 255) openfile starting @ 0 write thetext openfile starting @ eof unicode text end try try close access openfile end try end write_unicodewithbom on read_unicodewithbom(filepath) read file (filepath text) unicode text end read_unicodewithbom
Comments
Post a Comment