How to prevent zombies

This week, I have been attacked by zombies – half-dead apps which appear to have quit automatically, but aren’t dead at all until macOS removes them, possibly hours later.

Thanks to another regular reader, Michael Tsai, we may have rediscovered a means of stopping apps from entering this zombie state.

When the automatic quitting of idle apps was first introduced into OS X five years ago, a command-line workaround was discovered, which could control the feature globally, or for individual apps. For example, it is detailed in this archived article on krypted.com.

To prevent all apps from becoming zombies, simply type the following into Terminal:
defaults write -g NSDisableAutomaticTermination -bool TRUE

When you next open an app like Preview, if you leave it unattended in the background with no open windows, it will just sit there, and won’t quit or become a zombie.

If you want to set this for Preview, you can use the command
defaults write -app Preview NSDisableAutomaticTermination -bool TRUE
instead.

Reversing this is also simple: use the same command, only with FALSE instead of TRUE. The old command to delete the setting doesn’t seem to work any more, though.

To read back the setting and check that it is correct, enter
defaults read -g NSDisableAutomaticTermination
for the global setting, or
defaults read -app Preview NSDisableAutomaticTermination
for just the one app. A result of 1 means it is set to TRUE, and a 0 means FALSE.

This will stop these apps from being turned into zombies, and prevent them from automatically quitting. You will then, of course, have to remember to quit them when you don’t need them any more. Otherwise it seems quite harmless.