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.
- Full guide: README on GitHub Gist
- Script: lock-saved-apps.sh on GitHub Gist
What worked for me
-
Give your terminal app Full Disk Access:
“System Settings > Privacy & Security > Full Disk Access”.
Turn on Terminal (or iTerm), then quit and reopen it.
-
Copy the script from the gist below and save it as
lock-saved-apps.sh. -
Run it:
chmod +x lock-saved-apps.sh ./lock-saved-apps.shIt asks for your password. When it’s done, both lines should say
LOCKED.
How to test
- Open a few apps.
- Open Activity Monitor.
- Search for WindowServer.
-
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.