TextEdit Removes BOM from Unicode Files – How to Fix

snow leopardtexteditunicode

I'm working with UTF-8 files, but TextEdit seems to not fully support the BOM. When a BOM is present, it DOES render unicode characters correctly. However, upon saving the file, the BOM is removed, so subsequently opening the file in TextEdit causes 'the wrong' characters to be displayed.

Is there a way of remedying this? Bear in mind I'm sharing files with several non-technical users, so anything related to the command-line is out of the question. If the solution is 'use another text editor', this might just about be acceptable, if it's free, and not totally different from TextEdit – i.e. the simpler, the better. But, ideally, there's a way of fixing TextEdit …

Best Answer

TextEdit → Preferences → Open and Save

Screenshot

Set “Plain Text File Encoding” to “Unicode (UTF-8)” for both opening and saving files.

If that doesn’t fix it already, open Terminal.app and enter the following:

echo "0x08000100:0" > ~/.CFUserTextEncoding

Then logout and login again.

This fixes the ancient UTF-8 bug in OS X that also manifest in QuickLook.

To fix it for just a single file rather than for all files (I don’t see why you would, though), just write the extended attribute that TextEdit uses:

xattr -w com.apple.TextEncoding 'UTF-8;134217984' filename.txt

Hope this helps!