File type metadata in OS X
The official Apple recommendation to developers regarding the storage of file type metadata in Mac OS X (as expressed in the Mac OS X System Overview document at the time of this writing) is as follows (emphasis added):
- Type and creator codes stored as attributes of a file (if it is created on an HFS or HFS+ volume)
- One or more file extensions relevant to the type (for example, .html and .htm)
First, I want to address the mention of file creator metadata in the passage quoted above. Creator metadata is distinct from file type metadata, despite its inclusion in Apple's description of file typing. It is used by Mac OS X during the application binding process, but it does not factor into any determination of a file's type.
File type metadata in Mac OS X is specified in two places rather than just one. But is this merely the redundant storage of file type metadata, or is file type determined by the combination of the two pieces of information? In other words, do I need to know both the file name extension (e.g. "
.txt") and the file type code (e.g. "
TEXT") in order to determine with certainty that a file is a text file? Or will either of those pieces of information suffice in its own? And if I only need one of the two pieces of information, can the other be omitted?
The answer to the first question is clear. Knowing either the file type code or the file name extension is sufficient in Mac OS X to determine the file type. That being the case, can one or the other be omitted? Apple says the following:
Apple recommends that your applications make use of both forms of document typing. [...] Your application should enforce the setting of all valid types for its documents, particularly file extensions.
The message is clear: applications must set both file type codes and file name extensions when saving files. Note that Apple asks developers to pay particular attention to the addition of file name extensions. Apple knows that many Mac developers do not like being forced to encode file type information in the file name. Apple addresses the issue as follows:
Why even have extensions?
Some Macintosh software developers react to file extensions with dismay. As a means for specifying document type and ownership, extensions seem primitive compared to the type and creator codes and the other rich metadata made possible by the multi-forked HFS and HFS+ volume formats. Using extensions seems to be a step backwards.
Apple has broadened the scope to include not just file type metadata, but also the concept of file "ownership." Apple also includes resource forks in the discussion, despite the fact that they are primarily a data storage mechanism, are not used to store type and creator codes, and have been officially deprecated in favor of resource files earlier in the same document. Apple continues:
This is true, but only in a limited context. Macintosh users do not live anymore within a parochial Macintosh world. In the Internet age, documents frequently travel around a heterogeneous network, going, for instance, from a home Macintosh to a Linux network server to a Windows computer on a corporate local area network. Each computer on this path may have a different notion not only of what constitutes a document type but what constitutes a file. Many computer systems define a document's type solely by well-known extensions (such as .jpg, .mp3, and .html). They might not know what to do with an extension-less file and treat it as an unknown type. They would also ignore the HFS+ metadata--or worse, strip it out altogether, so that it is irretrievably lost.
For readers of this article, the passage above should not be new information. But attentive readers will also note that the fact that other platforms encode file type information in the file name does not necessarily mean that the Mac applications must also do the same when saving files locally. As we've seen, Apple recommends that Mac applications also store file type codes, which are sufficient on their own to determine file type on the Mac platform. And when sending files to other platforms, the operating system has enough information to append the appropriate file name extensions.
Instead of encoding file type metadata in the file name "just in time" when sending files across platforms, Apple recommends that applications do so when the file is first created.
The reaction to this recommendation from some Mac users and developers has not been kind. Years of Mac use has made many Apple customers accustomed to complete "ownership" of the file name. The clean metadata storage mechanism of the Mac has traditionally enabled Mac users to choose file names without worrying about other pieces of file metadata, especially immutable pieces like file type that have no relation whatsoever to what they want to name their files. And now Apple is recommending that all Mac OS X applications append file name extensions when saving files?
As you have no doubt guessed, I am one of the Mac users that thinks no Mac application should ever force the user to save a file with a file name extension. If the file type information stored in the 32-bit type code is sufficient for my Mac to determine a file's type, why should I be forced to pollute my file names with a fragile, redundant copy of that same information? Doing so eliminates one of biggest user experience advantages of using a Mac.
More from Apple:
A user can later change or remove the extension (and pay the consequences for doing so), but your application should always apply all valid forms of document typing, including extensions, when it saves its documents.
The "consequences" of removing a file name extension are actually determined by Mac OS X applications, not by the operating system itself. If I email a Photoshop document named "
Logo (Second Revision)" to a Windows user and my email application does not encode the file type information in the file name by appending the appropriate "
.psd" file name extension, then the recipient may have trouble opening the file.
Unfortunately, Apple does not recommend that applications that move files across platforms behave in this manner. Instead, as we've seen, Apple recommends that Mac OS X applications encode file type metadata in the file name as soon as the file is created. This "solves" the interoperability problem in that any file created in this manner can be sent to another platform without encoding file type metadata in the file name at the time of the transfer. But it requires Mac users to live with file name extension the rest of the time as well.
I find this solution unacceptable, as do many other Mac users. Apple has been made aware of this, and plans to address the situation in the upcoming Mac OS X 10.1 release. Unfortunately, the proposed cure is worse than the disease. The following appears on Apple's web site:
File extensions help Mac OS X maintain full Internet compatibility, but they also add a layer of complexity for long-time Mac users who prefer working without them. Now you have a choice -- we've improved the experience by adding system preferences to turn off the display of these extensions.
Let's evaluate how well the option to hide file name extensions addresses the problem. Does it return full "ownership" of the file name to Mac users? No. It merely (optionally) further restricts user access to the file name by making a portion of it invisible and uneditable in certain situations.
The failure to actually fix the problem is bad enough, but this proposed feature also fails the Hippocratic oath of creeping featurism to "first, do no harm." In addition to doing nothing to address the concerns of Mac users who want to retain full ownership of the file name, the option to hide file name extensions actually introduces many new user experience problems of its own.
The first problem is best expressed by the now-infamous file name "
Funny.txt.vbs". As anyone who's had to do any PC support knows, this is a an example of a classic virus spreading technique. Although many versions of Windows hide file name extensions by default, Windows users are nevertheless accustomed to using and reading them. So when an email attachment named "
Funny.txt" shows up in a Windows email application, the user is likely to interpret it as a funny text document and then proceed to open it. If the email application hides file name extensions, the "
.vbs" extension that denotes a Visual Basic program is never seen by the user. He opens what he thinks is a funny text file only to find himself running a virus-spreading program instead.
The second problem has actually existed in Mac OS X since the 10.0 release, albeit in a much more limited form. Take a look at the screenshot below. (I made it big since it's the only one in the article; savor it ;-)
Your eyes do not deceive you. There are (apparently) two files named "
Finder" in the same directory. What's actually happening is that the "
.app" extension is hidden on one of them. In Mac OS X, the "
.app" extension indicates that a directory is really an application bundle. This is another case of metadata redundantly encoded in the file name, since the same information is also available by other means (via real HFS/HFS+ metadata as well as inspection of the XML property list inside the bundle).
There is no option to "unhide" the "
.app" extension in Mac OS X 10.0.x, so the user must live with the (rare, one would hope) possibility of two items with the same apparent name in a single location. If file name extensions may be hidden on any file, not just applications, the likelihood of running across this confusing situation increases dramatically.
Next, let's look at the some other applications of file metadata in Mac OS X.