Getting Mac OS X applications to close after last window closed

47

11

I know it's just a pet peeve, but I hate it that Mac OS X's Preview.app stays open when it has no windows open. Is there any way to make it close when its last window is closed?

Since I don't see any option inside Preview to make that happen, I imagine that the answer might be applicable to other programs that have similar … idiosyncrasies.

I realize that this is not outside the OS's interface guidelines. That is, I recognize that this isn't a bug that will be fixed. I'm wondering if there is some way to automatically close selected GUI applications that have no windows open.

wfaulk

Posted 2009-10-11T15:44:09.503

Reputation: 5 692

Answers

23

Try RedQuits:

RedQuits is there to help if you have ever tried to close an application with its red button and wondered why it is still open. With RedQuits, all programs now quit when there's only one window left for that program. If you want to quit and close all open windows of a program, just uncheck "Quit only when 1 window is left for that app." in the preferences.

msaied

Posted 2009-10-11T15:44:09.503

Reputation: 246

RedQuits closes the application if you click the red exit button, but not when closing the last window using Cmd+W. – Sampo – 2017-04-23T19:11:37.300

Awesome, Works like a charm, thanks! – JayPex – 2019-12-25T23:01:34.250

4What's funny is RedQuits itself doesn't quit when you press the red button, says so in the instructions. It's simple, which is nice, but no white list. – Michael Ozeryansky – 2013-01-06T18:02:33.450

23

In short: No.

--Answer stops here. Everything following is just my attempt to explain why.

What you are experiencing is the Mac philosophy of how applications should behave. Those who are closed after the last window dissapears are not behaving to Mac Interface Guidelines (though there are a lot out there). // Edit: This is not entirely correct, see posts below.

It has been that way since the very first Mac System (in 1984). I guess it'll stay with us for another 25 years to come. Maybe app devs will allow us to set that in the preferences.

Until then it helps getting used to Command-Q (the Apple key and q) to quit each and every app - and Command-W for just the active window.

Wolf

Posted 2009-10-11T15:44:09.503

Reputation: 2 425

also, I am starting to use a Mac, and I don't get why apps with no opened window appear in the list when switching tabs with command-tab... Just, why? What was the idea behind this really? – Romain Vincent – 2019-01-05T18:42:09.327

I hate this behaviour - I set safari to reopen last session, but it only works if I remember to quit it instead of closing it. If I close it, I will loose my session and next safari window is empty. Same for sublime text or any other app that I expect to keep it's session after years of getting used to it. Btw on my Linux the quitting shortcut is Ctrl+Q, so it's not that far off compared to Windows, but it's still less convenient to press when my muscle memory is learned to Ctrl+Q (I have to use different fingers now basically). – jena – 2019-10-10T09:03:24.687

1My personal opinion as a comment: Working with both platforms every day: I got used to it. Doesn't make that much difference at all and - as always - there are two sides to it. While the app is running, each subsequent start is super-extremely-quick. Those apps that I use just once in a while could just as well be closed right after I use them.

I got used to Apple-Q/Apple-W on the Macs much faster than Alt-F4/Strg-F4 on the Windowsers. – Wolf – 2009-10-11T16:26:02.350

29One can also press Q while using Command-Tab to switch applications (thus while still holding down Command), to quit the application that is currently highlighted in that application switcher. – Arjan – 2009-10-11T16:32:19.500

+1 for Arjan's comment. It's an amazing way to close a huge number of apps at once. You do this whenever you need to free up some memory. – Dan Rosenstark – 2009-10-11T17:22:32.267

Actually, using the Application Switcher is the only time that open applications bother me. Too bad hiding applications does not keep them away from the application switcher. – Arjan – 2009-10-11T18:03:06.837

2What really, really annoyed me was that minimized apps showed up in the app switcher, but wouldn't be restored if choosing them. That I found very inconsistent. Just recently - after literally years of usage - I came across pressing ALT while switching to the (minimized) app would restore it. Hooooray!!! – Wolf – 2009-10-11T20:46:50.390

@Wolf: you have your descriptions mixed up : windows are minimized, applications are hidden – Steve Folly – 2009-10-11T23:26:48.227

15To be brutally honest, I'm not all that interested in whether or not the symptom is normal. I'm interested in how to get rid of the symptom. – wfaulk – 2009-10-12T16:26:35.753

@Steve: Absolutely correct. Thanks for pointing it out. Unfortunately I can't edit/correct my post. – Wolf – 2009-10-12T20:18:12.527

The accepted answer shows that your response is incorrect. – wfaulk – 2013-03-11T20:19:27.437

3

The automatic termination feature introduced in 10.7 partially addresses that for some applications.

If you open Preview, open at least one window in it, close all windows, and switch to another application, Preview is hidden from the Dock and application switcher. If you look at Activity Monitor, the process is still running and uses memory, but there might be some changes in how the process is managed.

The Mac App Programming Guide says that processes are actually terminated, so there might be something I'm missing.

  • Automatic termination eliminates the need for users to quit an app. Instead, the system manages app termination transparently behind the scenes, terminating apps that are not in use to reclaim needed resources such as memory.

[...]

Automatic termination transfers the job of managing processes from the user to the system, which is better equipped to handle the job. Users do not need to manage processes manually anyway. All they really need is to run apps and have those apps available when they need them. Automatic termination makes that possible while ensuring that system performance is not adversely affected.

Lri

Posted 2009-10-11T15:44:09.503

Reputation: 34 501

1Preview certainly doesn't automatically disappear for me under those conditions on 10.7.4. – wfaulk – 2012-12-18T17:18:59.337

I missed your comment earlier, but it does for me in 10.8.2. Did you open at least one window (like open and close the preferences window) before hiding Preview? – Lri – 2013-03-10T01:34:43.777

3

I wrote an AppleScript application to do this for you.

In brief, it checks what applications are open, gives you the option to whitelist apps to be excluded from auto-quit, then every 60 seconds, quits all applications (that it can, due to limitations).

To alter the whitelist while it's running, click the icon in the dock for the selection dialog to reappear.

To quit, right click the Dock icon and choose "Quit"

AppleScript source and Application: http://files.me.com/kioarthurdane/6kjl9k

dotHTM

Posted 2009-10-11T15:44:09.503

Reputation: 1 534

Seems like a good idea, except it doesn't work. I had to change "name" to "displayed name" in refreshWindowedProcess() to keep it from asking "where is this application", but even then it doesn't seem to ever quit anything. – wfaulk – 2009-10-27T03:37:14.943

What version of OS X are you using? I wrote my script under Snow Leopard, not sure if there have been major changes to AppleScript. – dotHTM – 2009-10-27T17:00:06.660

Nevermind, OmniGraffle Pro just did it to me. Very funny those cases were the name in Finder is not the actual file name... I'll see if I can write a correction to this using the bundle identifiers instead. – dotHTM – 2009-10-27T17:06:43.467

Updated using bundle identifiers instead of application name (which can be different than the application's filename).

In the source, there's a note about two lines commented out that will report the list of windows in each bundle identifier. I notice that many applications report having at least one window open despite no visible window being open. NetNewsWire is one such app having a long list of windows even after the main window is "closed". The Hit List is another app that retains it's single window is always open. – dotHTM – 2009-10-27T19:15:27.667

Count of Windows = 0 seems the most obvious way of detecting your state for quitting, but this does not seem to do the job for all apps. Come up with your own conditions to add to my code. Since not all applications have an AS dictionary, it will be hard to check those apps for any other conditions (let alone time consuming to make a separate rule for each one).

I'm more inclined to agree with the other answers given of "It's part of the Mac Culture to have a headless application still running" Unless it's doing something, it's not gonna be taking up much CPU or physical RAM. – dotHTM – 2009-10-27T19:16:18.807

2

Another free small and simple app, Quitter, displays an X icon in the traybar which acts just like the closing button under Windows.

Andreas

Posted 2009-10-11T15:44:09.503

Reputation: 21

4Welcome, and thanks for posting an answer! You should disclose your affiliation with the linked product/blog. It's not usually a problem when everything is kept above board :) – JoshP – 2012-12-17T16:07:24.617

0

Override the following method in NSApplicationDelegate (which normally returns NO):

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

Pierre Dufresne

Posted 2009-10-11T15:44:09.503

Reputation: 11

This is a question about how users might make this happen to existing applications, not how a programmer might get his program to do it. Thanks for your effort, though. – wfaulk – 2016-06-23T20:52:40.787