Uncheck "Reopen windows when logging back in" by default
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?
Solution 1:
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.
Solution 2:
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.
(click here for more information)
Solution 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.
Solution 4:
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/