19

The shutdown/restart dialog has a check-box Reopen windows when logging back in which is checked by default. I need to change its behavior to be unchecked by default. Is this possible? If yes, how can I do that?

enter image description here

0

7 Answers 7

9

Edit: since 10.7.4, the "Reopen windows when logging back in" checkbox has stayed unchecked if you uncheck it once, so the hacks below are not needed anymore.

One option is to set the LoginwindowLaunchesRelaunchApps key to false in ~/Library/Preferences/com.apple.loginwindow.plist:

defaults write com.apple.loginwindow LoginwindowLaunchesRelaunchApps -bool false

You could also save this property list as ~/Library/LaunchAgents/logout_saves_state.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>logout_saves_state</string>
    <key>ProgramArguments</key>
    <array>
        <string>defaults</string>
        <string>write</string>
        <string>com.apple.loginwindow</string>
        <string>TALLogoutSavesState</string>
        <string>-bool</string>
        <string>false</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

Then load the property list by running launchctl load ~/Library/LaunchAgents/logout_saves_state.plist or by logging out and back in once.

TALLogoutSavesState sometimes got reset to true when I logged out and back in, so just running defaults write com.apple.loginwindow TALLogoutSavesState -bool false once wouldn't have worked.

Neither of these options actually makes the checkbox appear unchecked, but they have the same effect.

1
  • I found a reason to still do this on 10.7.5: the box in the Restart dialog is now unchecked by default, and state is not restored. But if I forced a reboot by holding down the hardware power button on my MacBook, it restored state. After applying this fix, when rebooting with the button, I now get a dialog upon reboot that says "You shut down because of a problem. Do you want to restore state?", so I can get a clean reboot. Oct 18, 2012 at 0:42
4

This bug has been fixed with the Lion update 10.7.4:

The OS X Lion v10.7.4 Update includes fixes that:

Resolve an issue in which the "Reopen windows when logging back in" setting is always enabled.

enter image description here

(click here for more information)

3

For Mojave, none of the options above worked for me, however, someone else mentioned the following, and it's sufficient for me:

Close all windows, except terminal, and run:

chflags uimmutable $HOME/Library/Preferences/ByHost/com.apple.loginwindow.*

Terminal and Finder will now be the only apps which will open on reboot.

2

No, it is always set to "on." However there does exist a script you can run, that disables the feature. The box will still be checked, but the feature will no longer function:

Paste the following into a single line within the Terminal:

curl http://goo.gl/Z4EFC -L -s -o ~/fixlogin.sh && chmod +x ~/fixlogin.sh && sudo ~/fixlogin.sh ; rm ~/fixlogin.sh

That command downloads a script, places it in the appropriate location, makes it executable, and then removes the temporary file. If you are wondering, the contents of the downloaded bash script are the following:

#!/bin/bash
echo "#!/bin/bash" > /tmp/loginfix.sh
echo "rm /Users/*/Library/Preferences/ByHost/com.apple.loginwindow.*" >> /tmp/loginfix.sh
mv /tmp/loginfix.sh /usr/bin/loginfix.sh
chmod +x /usr/bin/loginfix.sh
defaults write com.apple.loginwindow LoginHook /usr/bin/loginfix.sh

If you ever want to revert back to the default behavior of this OS X Lion feature, just type the following defaults write command:

sudo defaults delete com.apple.loginwindow LoginHook

And you’ll be back to be able to select window restore based on that checkbox’s choice.

Source: http://osxdaily.com/

2
  • You can also disable Resume for applications on a per app basis. See these answers here.
    – gentmatt
    Dec 24, 2011 at 12:39
  • Thank you for the script, it fixes one of the most annoying "features" of the latest Macs.
    – Tobia
    Aug 4, 2014 at 8:04
2

This has changed in Mac OS X Update Version 10.7.4.

Resolve an issue where the "Reopen windows when logging back in" setting is always enabled.

enter image description here

Here is the new option, as you can see (although it isn't proof in itself as it's easy to uncheck and then screen grab, but please trust me - I was pretty stoked when I checked out this update as this bug was really annoying me!)

enter image description here

1

For the record, we’re talking about this:

Screenshot

The problem is that OS X doesn’t remember if you uncheck the checkbox on the last shutdown — it will always keep the checkbox checked by default on subsequent shutdowns.

I found two different solutions for this problem, that seem to do the trick, although they aren’t ideal.

Open Terminal.app and enter the following commands:

defaults write com.apple.loginwindow TALLogoutSavesState -bool false
defaults write com.apple.loginwindow LoginwindowLaunchesRelaunchApps -bool false

This effectively disables the “reopen windows when logging back in” option, although the checkbox will still appear to be checked. You can just ignore it.

I’m afraid there’s no better solution, at least not at the moment.


It’s possible to disable Resume on a per-app basis, too.

There’s also a system setting that allows you to disable it for all apps, system-wide. Go to System PreferencesGeneral:

Screenshot

Alternatively, you can run this command in Terminal.app:

# Disable Resume system-wide
defaults write NSGlobalDomain NSQuitAlwaysKeepsWindows -bool false

(Taken from my .osx file.)

4
  • TALLogoutSavesState sometimes gets reset to true after logging out and back in though. defaults write com.apple.loginwindow TALLogoutSavesState -bool false would need to be run at login using a launchd agent or something.
    – Lri
    Mar 21, 2012 at 12:41
  • @Lri It seems to work fine for me, even after multiple logouts/reboots, in combination with the LoginwindowLaunchesRelaunchApps setting. I remember testing the two separately, in which case I ran in to the issues you described in your answer. AFAICT, there’s something about the combination of the two settings that does the trick. Mar 21, 2012 at 12:44
  • I just ran both again, logged out and back in twice, and defaults read com.apple.loginwindow TALLogoutSavesState returned 1.
    – Lri
    Mar 21, 2012 at 12:48
  • TALLogoutSavesState still gets set to true by itself. But just LoginwindowLaunchesRelaunchApps -bool false alone seems to be enough to disable restoring windows.
    – Lri
    May 10, 2012 at 17:56
1

Unchecking "Reopen windows when logging back in" did not resolve the problem for me. Apps were still reopening after restart from Apple Script, or with shutdown command in Terminal.

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

  1. Open Finder
  2. Cmd+Shift+G (Go to folder)
  3. Copypaste ~/Library/Preferences/ByHost/ and confirm
  4. Find the file starting with com.apple.loginwindow
  5. Doubleclick (opens in TextEdit)
  6. Remove all content and save the empty file. An additional confirmation dialog may appear.
  7. Right click, Get Info
  8. Lock the file (check the Locked 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.

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

CLI method

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

    sudo chown root ~/Library/Preferences/ByHost/com.apple.loginwindow*
    
  3. Remove all permissions, so it can't be read or written to

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

CLI method (undo)

  1. Re-enable "reopen all apps" after login

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

     


1
  • GUI method worked for me, somehow after performing CLI method the file was overwritten Mar 12, 2020 at 8:36

You must log in to answer this question.

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