4

To enable or disable the preservation of open files between launches, there's a global Preference/Setting.
up to Monterey
System Preferences > General > Close windows when quitting an app
Ventura onwards
System Settings > Desktop & Dock > Close windows when quitting an app

On Mac, this is known as a savedState. I can as a one-time option prevent any app from using its last savedState by holding Shift ⇧ as I launch it. I could discard the SavedState itself from ~/Library/Saved Application State/

But what if I just want one app, say Preview, to never save state, without having to disable this globally.

I'm writing this to be a googleable resource to an issue I once found the answer to, then completely forgot; which made it really hard to find again. Having re-discovered it, I wanted to nail it here, hopefully in searchable form.

1 Answer 1

4

If you can find the app's Bundle ID then you can control which apps will save their state between launches & which will not.
Bundle IDs are usually of the form com.company.AppName which should make them relatively easy to figure out without needing Terminal.

Preview, for instance is com.apple.Preview - that simple.
If you look in ~/Library/Saved Application State/ you'll find it's full of folders with this naming scheme, each with .savedState at the end to further identify what that particular folder is for.

Once you've figured out your Bundle ID, then all you need is one line in Terminal to change or check its current status -
defaults read com.apple.Preview NSQuitAlwaysKeepsWindows
This will return either a 0 for 'off' or a 1 for 'on'. If a value has never previously been set it will return an error The domain/default pair of (…) does not exist
To change the state type
defaults write com.apple.Preview NSQuitAlwaysKeepsWindows -bool false to switch off, or
defaults write com.apple.Preview NSQuitAlwaysKeepsWindows -bool true to switch on.
This value is read at launch, so quit & relaunch to register the change.

Done.
Your one app will now adopt this chosen behaviour, irrespective of your global setting.

If you ever want to revert this to the global setting rather than individual, then you need to delete the value rather than just switch it between true & false.
defaults delete com.apple.Preview NSQuitAlwaysKeepsWindows

These defaults are written to the appropriate preferences .plist file in ~/Library/Preferences/ so apply to only the current user.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .