xattr: com.apple.TextEncoding, reveals text file encoding

Type: com.apple.TextEncoding
Subtypes: none
Serialisation: none
Data type: UTF-8 string, containing encoding and an integer. Known encodings are given below.
Example: <7574662d 383b3133 34323137 393834> «utf-8;134217984»
macOS: El Capitan, Sierra, High Sierra
System use: very infrequent
App use: infrequent
Document use: extensively in text files (only)
Other usage: none

Purpose: indicates the encoding used for the contents of the text file.
Known values include:

  • «utf-8;134217984» = UTF-8
  • «utf-16;256» = UTF-16
  • «macintosh;0» = Macintosh (Classic)
  • «ISO-8859-1;513» = ISO-8859-1
  • «US-ASCII;1536» = ASCII
  • «windows-1252;1280» = Windows-1252

Note that these are case insensitive, so macintosh and MACINTOSH are identical.

Are these used by any Cocoa or other macOS libraries for text encoding recognition?

Tools: can be seen and set in better text editors, e.g. BBEdit. Also in xattred and xattr


Original page: 2017-12-10
Last modified: 2017-12-10