I’m trying to open a text file created with AppleScript, in FT. I get the following error:
“The document ‘.txt’ could not be opened. The text encoding of the contents couldn’t be determined.”
- If I try to open with TextEdit, TextMate, or SublimeText 2, it works fine.
-
file -I <filename>
confirms the encoding is “text/plain; charset=iso-8859-1”
- If I manually change the encoding to UTF-8 using
iconv -f
, it can be opened in FT
Am I doing something wrong in my script, or should FT be able to open this file?
Can you show us the creation line which you are using in Applescript ?
You should ideally be creating it in UTF-8, for example, something like:
on WriteText2Path(strText, strPosixPath)
set f to (POSIX file strPosixPath)
open for access f with write permission
write strText as «class utf8» to f
close access f
end WriteText2Path
This is how I create the file:
--WRITE THE FILE
tell application "System Events"
set save_File to open for access (save_File & ".txt" as string) with write permission
try
write url_list to save_File
end try
close access save_File
end tell
So i’m not explicitly setting the file encoding, but I assumed the default would work fine in most text editors. I’ll try your approach.
Just for my interest, does anyone know what the inherent issue with “iso-8859-1” encoding is? If Applescript uses this by default, shouldn’t text editors be able to read it?
I think there’s a geological rift there between Applescript’s pre-unicode past and OS X’s unicode present.
(iso-8859-1 is a Latin block – sounds like it may be defaulting to Mac Roman)
Always a useful reflex in Applescript now to write strText as «class utf8» to f
@dlehman I’m changing the code to be a bit more relaxed on what it reads for the next release, that should solve this issue.
I changed my script to explicitly set “utf8”, so i’m all good. But appreciate the excellent support, as usual!