Issue:
When I shut down or restart in Lion, it always asks if I want to “Reopen windows when logging in” and that option is selected by default (see screen grab below).
Unfortunately, I rarely want to do that (when I shut down my computer, I usually want it to start fresh next time). So, first I have to deselect that option. Then, to make it worse, the next time I reboot it still has the “reopen windows” option selected! (That is, Lion doesn't remember my preference between reboots.) You can't expect me to move the cursor around and click in a box every time I shut down my computer! Is there a way to permanently turn off the “reopen windows” feature?
Solution:
This is an aspect of Lion's “Resume” feature, which Apple considers to be a valuable, ummm, feature of Lion. So, fine, opt me in the first time I want to reboot, but, seriously, let me make a choice and then don't change it back every time!
Note that the “reopen windows” feature is not the same thing as the “Restore windows when quitting and re-opening apps” option that is available in System Preferences--General. The former restores all running applications and open windows between power cycles, while the latter refers to saving the state of closed applications between uses. Apparently, based on the number of complaints and proposed solutions scattered around the interwebs, I'm not the only person who is annoyed by the “reopen windows” behavior in Lion. I've narrowed down the proposed solutions to four recommendations, including... (1) ...the one I am using. As it turns out, there is a default keyboard shortcut to uncheck the “reopen windows” box: simply press the space bar. Like many others, I was initially really annoyed at just the fact that my preference was not remembered between restarts, but this shortcut actually alleviates my main complaint about the “reopen windows” behavior, which is having to navigate the cursor into the check box when using my laptop. However, if pressing the space bar is still too much to ask of you, then read on... (2) I almost considered using the scripting solution described at http://ikluge.com/2011/08/24/getting-rid-of-lions-application-restore/ and http://osxdaily.com/2011/08/25/disable-reopen-windows-when-logging-back-in-in-mac-os-x-lion-completely/. However, in the end, I disliked the fact that this solution permanently disables the “reopen windows” behavior until a preferences file is edited (see below). I wanted an easier way to turn it back on, since I thought of a use case for “reopen windows”: I often use my laptop at airports and on airplanes. In a situation when I have to shut down in a hurry while working, I might appreciate having everything restored for me when I restart. In such a case, having “reopen windows” as the default behavior is even desirable. (I also have some concerns about the security of creating a potentially hijackable executable script on my computer that is automatically run by root on login.) So, I'm not using the scripting option, but I did want to offer a few comments about it, since the web sites listed above provide a script that sets everything up for you, but not a lot of explanation about what is being done or why it works. First, the necessary component of the script (called fixlogin.sh) is the following two lines:
#!/bin/bashrm /Users/*/Library/Preferences/ByHost/com.apple.loginwindow.*
The first line specifies that this is a bash shell script, while the second line deletes the preferences file (for each user account) that “remembers” which applications were open at shut down. The cited location for fixlogin.sh is in /usr/bin/, but, in principle, this script could be stored anywhere (I'll use /any/path/ for my generic example). It does have to be made an executable file (chmod +x /any/path/fixlogin.sh). The truly important step is to edit a root preferences file to create a login hook - this is a feature of Mac OS X in which a script is specified to be run at login before anything else happens, which can be accomplished from the command line as follows:
sudo defaults write com.apple.loginwindow LoginHook /any/path/loginfix.sh
Thus, regardless of what happened during the preceding shut down or restart, this script will remove the list of applications to reopen before the operating system tries to reopen them at the next start up. This will permanently disable the “reopen windows” behavior. The check box will still appear during the shut down or restart behavior, but its status (checked or unchecked) will have no effect. To restore “reopen windows”, use the command: sudo defaults delete com.apple.loginwindow LoginHook
(3) A solution involving scripted applications is described (and the applications made available for download) at http://www.gizmoblurb.com/2011/07/cleanreboot/. This solution works by setting the value of the preferences keyword that controls whether or not the operating system will restore opened windows to NO, then immediately calling for a shut down via the Finder, bypassing the dialog box (which would otherwise reset the keyword value to YES by default). The pertinent command is defaults write com.apple.loginwindow TALLogoutSavesState -bool false
I don't like this solution since it adds complexity to the operating system - when I want to logout, shut down, or restart, I have to locate the appropriate icon (there is a separate application for each of these cases, whose icons I am presumably storing on the Desktop or in the Dock, etc), and click on it. Seems like more work than just pressing the space bar (solution #1 - see above). (4) Incidentally, a bonus solution at http://hints.macworld.com/article.php?story=20110918051930924 is to manually run the command listed above in solution #3, then change permissions of the relevant preferences file to disallow subsequent writing: chmod a-w ~/Library/Preferences/com.apple.loginwindow.plist
This also requires changing ownership of the preferences file to root, to prevent the operating system from restoring the write permission on the file and “fixing” it to re-enable “reopen windows”, sudo chown root ~/Library/Preferences/com.apple.loginwindow.plist
Again, kind of cumbersome to reverse this process, and the potential repercussions of assigning ownership of a user level preferences file to root are unclear.
OS Version Compatibility: Lion
Update Status: 23 November 2011 (added)
|
