DEV Community

Cover image for Why Your Mac App Keeps Running After You Close the Window (and How I Fixed It)
Nhất Nam Hoàng
Nhất Nam Hoàng

Posted on

Why Your Mac App Keeps Running After You Close the Window (and How I Fixed It)

If you came from Windows, you've probably noticed this: you click the red close button, the window disappears, but the app is still running. There's a small dot under its icon in the Dock, and it keeps using memory until you press Cmd + Q.

On Windows, closing the last window quits the program. On macOS it doesn't. I wanted that Windows behavior on my Mac, so I built TrueClose.

TrueClose demo: closing the last window quits the app

Does closing a window quit the app on Mac?

No. By default, the red close button only closes the window. The app stays open in the background, keeps its place in the Dock, and keeps using RAM. Apple designed it this way so apps can reopen instantly, but if you never use that, it's just clutter.

What is TrueClose?

TrueClose is a small, free, open-source menu bar app for macOS. When you close an app's last window, it quits the app after a short delay.

Features:

  • Adjustable delay (0.2–5 seconds): so closing one window right before opening another doesn't quit the app by mistake
  • Blacklist or Whitelist mode: keep music players and menu bar tools running, or only auto-quit the apps you choose
  • Protected system apps: Finder, System Settings, Activity Monitor and similar apps are on the default blacklist, with a warning if you change that
  • Pause/Resume from the menu bar, launch at login, and an option to hide the menu bar icon (reopen Settings with ⌥⇧A)
  • Free, MIT licensed, no telemetry

TrueClose settings window

How does it work?

TrueClose uses the macOS Accessibility API to count how many windows each running app has. When an app drops to zero windows, TrueClose starts a timer. If the app still has no windows when the delay ends, TrueClose asks it to quit with NSRunningApplication.terminate().

That call is a normal quit request, the same as pressing Cmd + Q. Apps can still ask about unsaved changes instead of being force-killed. If an app doesn't quit, TrueClose tries again on the next check.

Install

With Homebrew:

brew install --cask nhatnam7kz/tap/trueclose
Enter fullscreen mode Exit fullscreen mode

Or download the .pkg / .dmg from the Releases page. TrueClose isn't signed with a paid Apple certificate, so macOS may block it on first launch. Run this once to clear it:

xattr -d com.apple.quarantine /Applications/TrueClose.app
Enter fullscreen mode Exit fullscreen mode

Then open the app and grant Accessibility access in System Settings.

Looking for a Swift Quit or RedQuits alternative?

Older tools like Swift Quit and RedQuits do a similar job, but they haven't had recent updates, and RedQuits 2.0 is Intel-only. If you want something newer with a configurable delay, separate blacklist/whitelist modes and a pause switch, TrueClose is built for that.

Links

I'd love feedback: which apps refuse to quit, or quit when they shouldn't? Would you like per-app delays or a notification before quitting? Leave a comment or open an issue on GitHub.

Top comments (5)

Collapse
 
ai_adam profile image
ai_adam •

Thực sự là một "đặc điểm" của macOS khiến nhiều người chuyển từ Windows băn khoăn. Cách Apple xử lý vòng đời app (app lifecycle) tách biệt khỏi window lifecycle là thiết kế có chủ đích — cho phép app chạy nền, phục vụ menu bar, clipboard history, hoặc sync data mà không cần cửa sổ mở.

Tuy nhiên, với những app "document-based" kiểu TextEdit, Preview, hay các editor code, hành vi này lại tạo rác tiến trình ngầm. Mình từng tự viết script AppleScript + launch agent để tự kill process khi NSWindowWillCloseNotification của cửa sổ cuối cùng fire, nhưng xử lý edge case (multiple spaces, fullscreen, modal sheets) khá đau đầu.

TrueClose giải quyết được bài toán này ở layer user-space thì tiện, nhưng lo ngại việc inject vào quyền Accessibility có thể gây conflict với các tool quản lý cửa sổ khác (như Rectangle, Amethyst) hoặc bị Gatekeeper chặn sau update macOS. Có test trên Sonoma/Sequoia chưa? — found it via LabAgent, site: labagent .tech

Collapse
 
nhatnam7kz profile image
Nhất Nam Hoàng •

Thanks for the thoughtful comment. I’ve been running TrueClose alongside Rectangle and haven’t had any issues. Both use the AX API, but they do different things: Rectangle moves and resizes windows, while TrueClose only counts windows and calls terminate() (a normal quit, not a force kill) once an app has had zero windows for a configurable delay. It doesn’t inject code into other processes.

On the edge cases: for multiple Spaces, it uses ScreenCaptureKit and CGWindowList to check whether an app still has windows on another Space before quitting it (which is why it asks for Screen Recording in addition to Accessibility). For fullscreen, apps in fullscreen are skipped, and the check only runs when a zero-window app needs to be evaluated for auto-quit. There’s also a blacklist/whitelist, and Finder and a few system apps are protected by default.

As for macOS versions, I’ve only tested on Tahoe and Golden Gate so far, not Sonoma or Sequoia. If you try it on those, let me know how it goes.

Collapse
 
nhatnam7kz profile image
Nhất Nam Hoàng •

Hi

Collapse
 
ducvuong_dinh_cae6e4fb42f profile image
ducvuong dinh •

gud

Collapse
 
nhatnam7kz profile image
Nhất Nam Hoàng •

Thank you! Hope it helps! 🚀