Avoiding all apps reopening when OS X crashes
Permanently prevent macOS High Sierra from reopening apps after a restart

Works in macOS El Capitan, Yosemite, Sierra, High Sierra.

Solution: deny OS X access to the file it uses to store your session state.
It prevents reopening apps even after reboot/shutdown from Terminal, from AppleScript, and system crash.

GUI method


Open Finder
Cmd+Shift+G (Go to folder)
Copypaste ~/Library/Preferences/ByHost/ and confirm
Find the file starting with com.apple.loginwindow
Doubleclick (opens in TextEdit)
Remove all content and save the empty file. An additional confirmation dialog may appear.
Right click, Get Info
Lock the file (check the checkbox)


GUI method (undo)

If you wish to undo this change later and re-enable the feature, simply delete this file and the OS will recreate it.


Open Finder
Cmd+Shift+G (Go to folder)
Copypaste ~/Library/Preferences/ByHost/ and confirm
Locate the file starting with com.apple.loginwindow
Simply delete it


CLI method


Open Terminal.app
Make the file owned by root (otherwise the OS will just replace it)

sudo chown root ~/Library/Preferences/ByHost/com.apple.loginwindow*

Remove all permissions, so it can't be read or written to

sudo chmod 000 ~/Library/Preferences/ByHost/com.apple.loginwindow*



CLI method (undo)


Re-enable "reopen all apps" after login

sudo rm -f ~/Library/Preferences/ByHost/com.apple.loginwindow*