MacOS – way to quit an app when the last item is closed

applicationsmacos

When I'm working on MS Office 2011, when I close a document, spreadsheet, presentation, etc., the application stays open. This is confusing (to me anyway) and I find myself having to explicitly quit these apps all the time (to get them out of the way).

Is there a way to quit an app when the last item is closed?

Thanks in advance!

Best Answer

It's an implementation detail that the developer has to implement. In your example case, for Office, it's Microsoft.

Here is the Cocoa Objective-C code that allows the developer to implement this feature:

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
   return YES;
}

What you're observing is normal behavior on almost all applications on OS X and even the classic Mac OS. It's one of those things you should get used to on the Mac. However, these days, you are in luck that things are changing in your favor in Lion and probably later as OS X gains more features from iOS. As referenced in Lion Is a Quitter.

Lion will quit your running applications behind your back if it decides it needs the resources, and if you don’t appear to be using them. The heuristic for determining whether an application is “in use” is very conservative: it must not be the active application, it must have no visible, non-minimized windows — and, of course, it must explicitly support Automatic Termination.

Clearly, it looks like that version of Microsoft Office does not support Automatic Termination yet, but it may be coming.

So for now, the most you can do is check the program's preferences for options relating to quitting the application when it has no more windows open. Also, I encourage you to give Microsoft and / or any developer of apps feedback that you would like to see "quitting on last window closed" as a preference option or suggest they add support for Automatic Termination to their products.

Until then, just remember to use +Q when you are done with those applications that do not automatically quit when you close all its windows.