Tuesday, May 15, 2007

OS X File Name Subterfuge

While saving a file via the well known OS X file Save As dialog I noticed something really queer. The filename I had pasted in was magically altered to adhere to OS X's ideas on which characters are kosher for file/directory names!

Silent Substitution
To see the magic simply open TextEdit, create a new document (if you are not already presented with one) and add the following text to the document:

watch: this: space:


Now, select the text, copy it and save the file with the selected text as the file name.



Et voilĂ !

Subterfuge Uncorked
The dialog magically converts the colons to hyphens (-) to ensure that you don't have to go through he whole 'This filename is not allowed' error cycle needlessly. Brill.

The reason for the substitution is that OS X prohibits the use of colon characters in file/directory names because this character is used to represent a directory in the HFS+ file system.

According to the HFS+ spec you can use any Unicode or ASCII (including NUL) characters. OS APIs may limit some of these characters for legacy reasons.

I love subtlety.

No comments:

About Me

My photo
I love solving real-world problems with code and systems (web apps, distributed systems and all the bits and pieces in-between).