Skip to main content

Prevent apps and windows from reopening on Mac

One of the most annoying macOS features, and one of the hardest to turn off:
when WindowServer crashes (or you force-quit it), macOS logs you out, and as
soon as you log back in it reopens every app you had running. The “Reopen
windows when logging back in” checkbox doesn’t help, because you never see
the logout dialog.

What worked for me

  1. Give your terminal app Full Disk Access:

    “System Settings > Privacy & Security > Full Disk Access”.

    Turn on Terminal (or iTerm), then quit and reopen it.

  2. Copy the script from the gist below and save it as
    lock-saved-apps.sh.
  3. Run it:

    chmod +x lock-saved-apps.sh
    ./lock-saved-apps.sh

    It asks for your password. When it’s done, both lines should say
    LOCKED.

How to test

  1. Open a few apps.
  2. Open Activity Monitor.
  3. Search for WindowServer.
  4. Select it, press the Stop button (the X in the toolbar)
    and choose Force Quit.

The screen goes black and you land on the login screen. Log in, and only
your login items should start.

Finder still opens its old windows?

Finder always comes back, but you can make it start with no windows:

defaults write com.apple.finder ApplePersistenceIgnoreState -bool true
killall Finder

Changed your mind?

./lock-saved-apps.sh unlock

Everything goes back to how it was.

Lock saved apps bash script:


View the script on
GitHub Gist.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please don’t paste any HTML, Js or PHP code into comments box, use pastebin.com or similar service to share code examples.

Characters left: 1000