About | ACP | Buy | Forum | Industry Watch | Learning Curve | Search | Twitter | Xnews
Home » Learning Curve

Bundles

A look at OS X application architecture.


Buy It

Try It

When is an application not an application? When it's a folder of course. Go to /Applications and look at all your pretty applications. Guess what? They're not applications at all - they're folders.

Ctrl-click on any of them. You'll see the item Show Package Contents. Pick one - pick iChat if you have it - and click it.

Now what do you have? A folder called Contents. Fun, huh? OK, double-click that one. Now you should see one or two nondescript files and two more folders, MacOS and Resources. Forget the files for now - double click the MacOS folder. What's in there? Can you guess?

That's your application. At least the bare bones of it. That's what actually runs. That's the PowerPC executable code.

Try double-clicking the icon. It doesn't start anything, does it? You get a message that the system doesn't know what to do with it. It wonders if you know what application you want to use to open the file. OK, try being difficult. Use the ensuing dialog to choose the same file again. Not much better, is it?

OK, time to get nasty. Open a Terminal window, navigate to /Applications, and list what you have there. Use the following two shell commands and then turn the page.

cd /Applications
ls -al

NeXTSTEP Apps

You should see a listing for your application (iChat) - the only difference from what you saw in the Finder is that this one has .app tacked on the end. Change directory to that '.app' directory and list everything again.

cd iChat.app
ls -al

What do you have now? Contents. OK, so change directory to Contents. And now you should have MacOS and Resources, exactly as you had in the Finder. So far so good.

Now change directory to MacOS, list the files again, note the name of your app (iChat), this time with no .app extension.

This is a NeXTSTEP idea you're looking at - the .app folder that passes for an application. It's now being used on the Mac.

Inside Bundles

The NeXTSTEP idea was rather elaborately sketched. A part of the rationale was to avoid crisis situations where apps are being moved about and no one knows what files they're supposed to stay connected to. By connecting everything under one folder that looks like an application things don't get that messy.

There's also portability built in there. You might reasonably wonder why you need the MacOS folder, because everything is MacOS, right? But there's a wealth of knowledge in that Resources folder, as you shall see.

Now that you're through struggling with your Terminal, quit it and come back to the Finder. Mission accomplished there. Back up to your Contents folder again, and this time double-click on Resources instead.

Unless things are totally wacky, you should see at least one more folder - something ending in lproj. If you're running OS X in English, you most likely will have at least the English.lproj folder. You might have more. Double-click English.lproj.

Language Project Files

The language project files (lproj extension) give NeXTSTEP its internationalisation.

OS X can run in a dozen languages - from English to Danish, Swedish, Finnish, to Dutch and German, to French and Portugese, and even mainland (Zhongwen) and Taiwan Chinese. That's quite a trick. And it's the lproj files that make it possible.

You can set your preferred languages in System Preferences; then when it's time to launch an application, the Finder looks for the language files corresponding to your choices.

But that's only the beginning of the story. If you double-click one of your lproj folders, you'll find NIB files within. NIB stands for NeXTSTEP Interface Builder. Interface Builder is one of the two major development tools for the NeXTSTEP platform. Interface Builder gives shape to your application windows and sets text fields in a variety of languages.

But even the NIB files can be folders - try Ctrl-clicking on one or more. At least one should offer Show Package Contents. Show the package contents, and you should find further NIB files - and these are most likely not folders, but real files - finally.

So when you double-click on what you thought was an application - what in reality was a folder, and a special folder at that - the Finder searched down through the Contents subfolder for a folder matching your hardware platform, found the actual program file, then checked your language preferences and searched the Resources subfolder for the lproj folder matching your language, then found the NIB files, and at least in one case saw this also as a folder, went down through that and loaded the real NIB files - and then, finally, started your application.

Thanks But No Thanks!

You're probably thinking a number of things right now.

  • That seems like an awful lot of work just to start an application.
  • I don't speak twelve languages - do I want all those other language files?
  • Mac is the only platform OS X runs on, so why have a MacOS folder at all?

They're all valid points. It is a lot of work, but in today's world - or already back in the late 1980's when this system was devised - you need to implement it in one way or another. This is just one way of doing it. The engineers at NeXTSTEP thought this was the best way. And it might be.

But such convenience does come at a price. The only file system OS X will currently run on (and no, we cannot consider UFS) is Apple's own HFS Extended (HFS+). This file system inherits enough of the traditional Mac disk architecture to make OS X work.

But HFS+ uses 4KB clusters. That means that the smallest disk allocation - even for a file with a single byte - is going to be 4KB or 4096 bytes.

Disk slack is a type of waste. Disk slack represents allocation space on your hard drive that you can never use. None of the folders in this '.app' hierarchy need much disk space, but they end up taking a lot.

Calculating The Waste

Your applications will not need to use that much disk space - not well-written ones at any rate. And your resources - your real NIB files - won't need to use much either. The PowerPC RISC processor is not that extravagant, and the resources for your program can be stored very efficiently.

But on smaller apps, your NeXTSTEP folder hierarchy can eat up as much disk space as the actual code. If it weren't for this 'Cocoa' scheme (and Carbon apps don't use it), then you could put all your apps in the same folder, and they wouldn't be .app folders, they'd be real applications.

But Cocoa apps - that is NeXTSTEP apps - will automatically use at least six folders just to exist on disk. That's 24KB of almost pure unused disk slack per application. Multiply 24KB times the number of applications you have on disk to see how much disk space is being wasted.

Your language folders are another matter, for they have contents - but contents you most often will not ever use. Estimates are that over 200 MB of disk space is wasted on unused OS X language files.

Yes, it is cool - for a few minutes at least - to be able to switch from English to mainland Chinese, but you normally won't be doing this every day, and certainly not with all twelve languages.

So reasonably those folders have got to go.

No Habla Espanol

Try this experiment to find out how many language folders you have. Open a Terminal window and input the following.

sudo ls -R / | grep English\.lproj | wc

This will take quite a while to run, so kick back. Make a note of the second figure and then do the following.

sudo ls -R / | grep *\.lproj | wc

When this operation is finished, take the second figure here and subtract the figure you saved from the first command. That's the number of extraneous lproj folders you have in your system. (The total number of extraneous files is of course greater still.)

But how do you get rid of them? If you're lucky, then you installed a later version of OS X that gave you a chance to opt out of these language files. If you are not lucky, you are running a new piece of Apple hardware with the OS already installed and you've most likely got them.

And if you installed a new OS X over your factory issue, then all the files that are already on disk are going to stay. The new install will let you stop putting more on your disk, but it won't take any that are already there away.

Getting Rid Of 'Em

There are a number of ways you can get rid of extraneous language folders.

  • Brute force with the Finder.
    Start at /Applications and go through every .app folder.
    This can take a while.
  • Brute force with a Terminal window.
    Once again you start at /Applications and work your way downward.
    This will also take a while.
  • Pick up a copy of Monolingual.
    Monolingual is a free app found at most Mac resource sites.
    But caution is advised: Monolingual uses a Perl script which can hose your system if you are not careful.
  • Wipe your disk and reinstall.
    Surprisingly, this may be the easiest method. Just make sure you have all important stuff backed up, then get out your installer CDs.

The NeXTSTEP system for internationalisation is not bad in itself, and neither is the Apple file system HFS Extended; but put together they can end up wasting a lot of your disk space.

You should be aware that these files are on your disk and that you normally will not need them. Thankfully Jaguar and later versions of OS X let you opt out of having them around.

Stragglers & Slackers

You'll find that even if you take the 'purist' approach and start with a clean install that some unnecessary language folders will end up on your disk anyway. Most of the time this is because the software in question is not Apple's own.

  • Microsoft Internet Explorer.
    For some weird reason, IE packages both Swedish and English together for the English speaking North American market. Even after a clean opt-out install you'll find any number of Swedish.lproj folders on disk.
  • Adobe Acrobat Reader.
    This application is notorious for wasting disk space. A standard install takes nearly 80 MB - and you probably won't use it much anyway, as you have Preview which does so much more. Consider putting Acrobat out to pasture.

But with only third party software wasting your disk space, you will still be a lot better off. As stated, you can rescue up to 200 MB. And that ain't just a couple o' bits.

About | ACP | Buy | Forum | Industry Watch | Learning Curve | Search | Twitter | Xnews
Copyright © Rixstep. All rights reserved.