OS X design decisions. Terminate the app on last window close?

12,603

Solution 1

Per Apple's Human Interface Guidelines (a guide for Mac developers):

In most cases, applications that are not document-based should quit when the main window is closed. For Example, System Preferences quits if the user closes the window. If an application continues to perform some function when the main window is closed, however, it may be appropriate to leave it running when the main window is closed. For example, iTunes continues to play when the user closes the main window.

Solution 2

In general, never close a document based application when the last window closes. The user will expect to be able to open a new document without relaunching the application, and it will confuse them if they can't.

For non-document based applications, you need to consider a few things:

  1. How long does it take for my application to open? If it takes more than a second, you should probably not quit.
  2. Does my application need a window to be useful? If your application can do work without windows, you should not quit.

iTunes doesn't quit because, as Anne mentioned, you don't need a window to play music (question 2). It is also not based on Cocoa, so it is much more difficult to close after the last window, especially since it allows you to open windows for specific playlists so there are an indefinite number of possible windows to be open.

In my opinion, Address Book does not need to stay open. This could be a left-over design decision from older versions of OS X, or it could be that someone at Apple just thought it was better to leave it open (maybe so you can add a contact?). Both iTunes and Address Book provide access to their main interfaces through the Window menu, as well as a keyboard shortcut (Option+Command+1 for iTunes, Command+0 for Address Book).

Share:
12,603

Related videos on Youtube

dawg
Author by

dawg

"On the Internet, nobody knows you're a dog"

Updated on March 30, 2020

Comments

  • dawg
    dawg over 3 years

    Unlike Windows, GNOME and most other GUI's, OS X application programs do not all terminate if the main window (or all the windows) of that application are closed.

    For example, fire up Firefox, Safari, Word, or most document based apps. Either click the red dot in the corner or type cmdW to close the window. You can see that the menu of that program is still active, and the program is still running. With OS X newbies, sometimes you will see dozens of these windowless zombies running and they wonder why their computer is getting slower.

    With some document based programs, there is some sense to not terminating the application if it has no windows. For example, with Safari or Word, you can still type CmdN and get a new document window for whatever that application was designed to do: browse the web (Safari) or type a new document (Word).

    Apple is mixed with their design philosophy on this. Some close on the last window closed and some do not. Third party apps are even more mixed.

    There are other apps that do close when their red close button is clicked. System Preferences, Dictionary, the Mac App Store, iPhoto and Calculator do terminate when the sole or last window is closed. iCal, Address Book, iTunes, DVD Player do not terminate.

    What I find particularly annoying is the applications that do not have a logical "New Document" or "Open" function yet they do not terminate when the document window is closed. Example: fire up iTunes or Address Book and terminate the main window. There sits a zombie with no window and no function other than manually selecting "Quit".

    It is easy to close the application after the last window closes. Cocoa even gives you notification of that event. Just add this to your application delegate:

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

    My question is this: Is there any reason I should NOT terminate my application after the last window closes? Why is this so variable on OS X software? Unless the app has a "new" or "open" or some other clearly understood reason to not terminate with no window open, the failure to terminate seems like a bug to me.

    • Carl Norum
      Carl Norum over 12 years
      Why do you say 'they wonder why their computer is getting slower'? An inactive application is using no resources.
    • Agos
      Agos over 12 years
      Just a quick note: there is a perfectly sound reason to want to run iTunes windowless, I hope you understand what it is. Address book is weird, though.
    • dawg
      dawg over 12 years
      @Carl Norum: "An inactive application is using no resources" That would be news to me. Start a bunch of programs including Terminal. In Terminal, type top Sure looks like those programs are using resources to me! Sure seems to speed things up if I terminate a few programs -- even those that that have not been active for days. As I type this, Photoshop is in the background. I have not had a document open or had it active in days. It is using 5% CPU and 233MB of resident memory. Multiply that by 10 programs sitting there and that is noticeable effect on performance. Am I missing something?
    • Chris Cooper
      Chris Cooper over 12 years
      @Carl: When I have Safari open for a while with many windows, I can close all the windows and it still leaves my mac sluggish. Safari is sometimes eating 500MB or more, with no windows open. This definitely leaves a visible slowness until I actually close Safari, at which point my memory "usage" drops incredibly.
  • mcrider
    mcrider over 12 years
    Sorry, i totally glossed over your list of apps that close when you close the main window. I just tested them out, and i'm actually pretty surprised. System preferences makes sense, but why would iTunes stay open and not iPhoto when the main window is closed? I'd still maintain that iTunes is useful when the main window is closed (because you don't need to look at it for it to perform its function), whereas perhaps iPhoto is useless without the main window open (because there is no other way to interact with the app)
  • Anne
    Anne over 12 years
    Many native Apple applications actually close: Calculator, FontBook, PhotoBooth, Dictionary, AppStore, and so on.
  • dawg
    dawg over 12 years
    Yes, I think that is the right answer. Too bad it is not widely followed!
  • Dave
    Dave over 12 years
    Yeah, it appears it's really up to each developer. Perhaps Apple will enforce it better for App Store submissions.
  • Johann
    Johann almost 10 years
    Consideration #1 is a terrible reason to leave an app open! If it takes more than a second, it's probably a resource hog that the user doesn't want left open. This is like the quick start "feature" found in many applications which really just leads to yet another background process taking up resources and slowing things down.

Related