Explainer: file types

Perhaps the most distinctive and revolutionary feature of Mac OS is the Finder, and one of its fundamental abilities is to open a file without you having to tell it which app to use. That and much else depend on every file having a type – a designator in its attributes which is used to determine which app ‘owns’ it and should be used as its primary editor. This article explains how file types are determined in macOS: it’s all about UTIs.

Apple’s Uniform Type Identifiers, UTIs, are designed to identify what sort of thing an item is using a structured hierarchical taxonomy. Their most obvious role is in declaring different types of files, although they extend more generally. Common examples include
public.jpeg
which of course is a public type for JPEG images, and
com.adobe.pdf
which is for Adobe PDF documents. The latter indicates one area of ambiguity: some types like PDF are attributed to their originator, while others are considered to be public types.

UTIs

These types exist within a vast interconnected tree. For example, when I write a file of Swift source code, the .swift file has the type public.swift-source, which is a specialised type of public.source-code, which is both public.data and public.plain-text, which is public.text. When I open that file, LaunchServices first looks for an editor for public.swift-source files, but can ascend the tree as necessary and use an app designed to open text files of public.text more generally.

It’s often claimed that macOS depends on filename extensions to determine different types of file, but that’s incorrect: macOS is far more capable, and uses MIME types when downloading from the Internet, can still use old Classic Mac OS four-character type codes, but ultimately relies on UTIs.

This is easily demonstrated in Terminal. Type the following command
touch notypefile
to create a new file in the current directory without any extension or other clue as to what it is. Then look in Finder’s Get Info dialog, and you should see that macOS has already assigned it a default type which associates it with TextEdit. Inspect that file using my free utility Precize, and you’ll see that it has a UTI (listed in the Type entry) of public.data.

Now give it an extension which is unknown to macOS, such as .xyz, and inspect it again with Precize: its type has changed to something more cryptic like dyn.ah62d4rv4ge81u8p4. That’s a dynamic UTI, created on the fly by macOS to distinguish it as having a unique type, described in Get Info simply as a Document, but still with TextEdit as its default associated app.

Every item in your Mac’s file system has a UTI, which tells Launch Services what to do when you try to open it, for instance by double-clicking its icon. There is an exception to this, which forms a longstanding bug dating back to OS X 10.5 in 2007: some files may not return a UTI, but a NULL instead. This seems to be confined to sockets, which appear to be files but aren’t really.

Unfortunately, although discovering UTIs is key to dealing with documents which are treated as having the wrong type, there’s no easy way to find a file’s UTI in macOS. Thankfully you don’t need long reference lists to find out key information such as what a filename extension or MIME type represents in terms of a UTI: it’s all contained within macOS, if you know how to look using one of the tools listed below.

The correct answer to the question of what determines a file’s type is therefore a list:

  • UTI, e.g. com.adobe.pdf,
  • filename extension, e.g pdf,
  • OSType, e.g. PDF,
  • MIME type, e.g. application/pdf, or
  • Pasteboard type, e.g. Apple PDF pasteboard type.

While you can change a file’s type directly by giving it a different UTI, it’s far simpler to do that indirectly by changing its extension to one correct for the type, such as txt or text for a text file. The OSType refers back to Classic Mac OS, as it’s the four-character type system used before UTIs. MIME types are mainly used for Internet file transfers, and Pasteboards are used when copying chunks of data using the Clipboard, which relies on the same basic system.

Tools

Thomas Tempelmann’s free Launch Services, which includes an excellent UTI browser.
UTIutility and Precize, free from their Product Page here.

Apple documentation

UTI overview (archived)
Framework doc (current)
System-declared UTIs (current).