Lion: Terminal windows reopened on restart, even when I specify otherwise

Hippo Man

Hippo Man
In Lion, if I issue a Restart, all my Terminal windows get reopened after restarting, even if I uncheck the box next to Reopen windows after logging back on.

These Terminal windows get reopened right after I manually reopen my first Terminal window after restarting. Therefore, I think that this behavior has to do with Terminal, not with the general reopen policy of MacOSX.

Is there some sort of new, Lion-specific setting in Terminal which will cause Terminal windows to not be auto-reopened after restart?

Thanks in advance.
.​
 
Well, once you open up terminal, all the windows that were open the last time you quit terminal will open up again. Thus, you have to close each one manually.

If terminal is opening when you start up your computer. You can fix that by opening up terminal, find the icon in the dock. Right click the icon and then go to options and deselect "Open at login."
 
Thanks, icemanjc, but "Open at Login" is not set in the Dock icon for any of the open Terminal windows that I use. And yet, when I restart, they do reopen at Login, anyway.

This is a Lion-only problem, by the way. It didn't occur under Snow Leopard.

Is there a way to keep the Terminal icon from showing up in the Dock, in the first place? I'm guessing that if that icon didn't appear in the Dock, I wouldn't have this problem. The "Keep in Dock" option is not set in the Terminal Dock icon, either, by the way.

Terminal is the only program I use (out of several) which puts that icon in the Dock.
.​
 
Last edited:
I now have a reproducible scenario in Lion which illustrates this problem:

1. Uncheck Preferences->General->Restore windows when quitting and re-opening apps
2. Open up a few Finder windows.
3. Open up a few Terminal windows.
4. In the Terminal Preferences, disable everything related to Window Groups.
5. Do a Logout or a Restart. Uncheck Reopen windows when logging back in.
6. Relog in.
7. Open one Terminal window.

After step 6, all of the Finder windows which were previously open before Logout or Restart will also reopen. After step 7, all of the Terminal windows which were previously open before Logout or Restart will reopen, in addition to the single Terminal window which is manually opened after login.

The only way I can prevent this from happening to Terminal is to add the following two lines right before the final </dict> tag in /Applications/Utilities/Terminal.app/Contents/Info.plist:

<key>LSUIElement</key>
<string>1</string>

However, this has the undesirable side-effect of not showing anything about Terminal in the menu bar or the dock.

Note that none of this used to happen in Snow Leopard, Leopard, or Tiger.

Does this scenario clarify what might be going on, and does it perhaps suggest a solution?

Thanks.
.​
 
I got a solution for this problem from the Lion section of the discussion.apple.com site. Here's what I did to fix this problem:

  1. Open Terminal.
  2. Open up a Finder window to a work folder.
  3. In the Finder menu bar, hold down Option and select Go->Library.
  4. Navigate to Saved Application State and open it.
  5. Duplicate the com.apple.Terminal.savedState folder (it will create com.apple.Terminal.savedState copy).
  6. Drag com.apple.Terminal.savedState copy to the work folder.
  7. In the work folder, rename that to com.apple.Terminal.savedState.
  8. Delete all the contents of com.apple.Terminal.savedState in the work folder. In other words, that com.apple.Terminal.savedState folder should now be empty.
  9. Go to Terminal and issue a Quit Terminal.
  10. Depending on your system settings, the com.apple.Terminal.savedState folder might now have disappeared from Library/Saved Application State. If so, that is good. If not, delete com.apple.Terminal.savedState from the Library/Saved Application State folder.
  11. Drag the empty com.apple.Terminal.savedState folder from the work folder to Library/Saved Application State.
  12. Do a Control-Click on this com.apple.Terminal.savedState folder, and select Get Info.
  13. In the Info window, select the Locked checkbox, then close the Info window.

Now, the Terminal application will not save its state on restart, nor at any other time.
.​
 
Why not just close any open applications before shutting down the operating system? It is just a good idea, and will minimize future problems with applications.
 
Of course, I can always manually shut down everything before reboot. However, in the past (up through Snow Leopard), MacOSX took care of that for me with a single confirmation mouse-click after I requested a shutdown or restart.

Now, with Lion, MacOSX is forcing me to do more work when I shutdown/restart, which goes against the idea of a computer being a labor-saving device.

But the fix I described above does work, so now, I can still use my computer the way I like.

Thanks.
.​
 
It isn't only Terminal that is the problem. Here is my fix:

In a Terminal window, type:

1) cd ~/Library
2) mv "Saved Application State" "Saved Application State.old"
3) touch "Saved Application State"

This creates a "Saved Application State" file instead of the folder that applications expect, and prevents them all from saving their state.

As well as fixing the Terminal, now Safari does't re-open all its windows on launch and try to reconnect to all of the old web sites that I had open. I really hated this too.

So now I am a happy camper again. Lion really doesn't look so bad any more.

- Phil
 
Thank you, Phil, for this simple solution.

However, in thinking about this, I realize that the Saved Application State folder is useful for keeping the states of various programs during the course of a login session. Sometimes during an individual login session, I want to restart an application and have it come up in the same state it was in when I previously closed it within that same login session.

I only want the saved states to be deleted on logout, so that when I re-login, I'm starting with a clean slate. For this purpose, I came up with the following variation of Phil's method:

  1. Open AppleScript Editor.
  2. Select File->New.
  3. Copy and paste the code for OnShutdown.app into the empty AppleScript Editor window (see the bottom of this post for the code).
  4. Click the Compile button, and make sure that there are no errors. If there are, make sure you copied and pasted the code for OnShutdown.app correctly.
  5. Select File->Save As...
  6. In the File Format drop-down, select Application.
  7. Make sure all checkboxes to the right of Options are empty except for the Stay Open checkbox, which should be selected.
  8. In the Save As box, name the program OnShutdown.app.
  9. Navigate to the folder in which you want to keep OnShutdown.app and select Save.
  10. Close AppleScript Editor.
  11. Open System Preferences->Users & Groups->Login Items.
  12. Make sure your user ID is selected.
  13. Click the plus sign ("+") below the list of Login Items.
  14. Navigate to the folder in which you stored OnShutdown.app, select that program, and click Add.
  15. Put a check mark in the Hide box to the left of OnShutdown.app in the list of Login Items.
  16. Close System Preferences.
You will have to log out and log in again before OnShutdown.app is completely installed. Then, the next time you log out or restart after that, OnShutdown.app will delete all of your application state, so that your session will start out with no programs running when you subsequently log in or restart.

Here is the code for OnShutdown.app:
Code:
on quit
        do shell script "/bin/rm -rf ~/Library/Saved\\ Application\\ State/* 1>/dev/null 2>&1"
	continue quit
end quit

PS: This only works if you haven't yet performed Phil's procedure. But if you have indeed already followed Phil's instructions, then just issue these commands within a Terminal window before installing OnShutdown.app:

Code:
/bin/rm -f ~/Library/Saved\ Application\ State
/bin/mkdir ~/Library/Saved\ Application\ State
.​
 
Last edited:
I've been searching for weeks for a way to stop my Terminal and Safari windows from opening up on login on Lion. All the basic suggestions - and even the thoughtful suggestions in this chain didn't work for me. I found the answer buried in the Apple Community site - so I'm pasting it here for everyone who, like me, has tried everything else:
-------

softwater Thailand
Re: How do I turn off Safari Resume?
Sep 12, 2011 1:37 AM (in response to Baron Sekiya)
Thanks to another user, I've now learned how you can turn of Resume completely. This is not the same as stopping Safari from starting up by opening your previous tabs. For that, use the commands I gave you above.

However, it will stop Safari, and anything else, from starting up when you reboot - what I love about this hack is it you don't even need to uncheck the box in the Login window!

All you do is this:

1. Close all windows and quit all apps.

2. In Finder, hold down the Option key and click 'Go' in the menu bar at the top.

3. Choose 'Library' (you have to have the Option key held down to see Library in the menu).

4. Navigate to Library > Preferences > ByHost > com.apple.loginwindow.[xxxxxxxxx].plist
The [xxxxxxxx] represent some interminable string of numbers and letters. What you need to check is that its 'loginwindow' and '.plist' at the end (don't make the same mistake as I did and choose the Unix exectuable file).

5. When you're sure you've identified the right file, select it and press Cmd-i to show the 'Get Info' window. Click the 'Locked' option.

6. Now, test that it works. Close the 'Get info' window and the finder window. Open up Safari, Preview and a couple of windows. Do a restart and behold - a clean desktop!

Huge thanks to Billearl who first posted this solution.
-------
There it was in my ByHost folder loginwindow preference file - a preference file which was overriding everything else. Thanks all.
 
I got a solution for this problem from the Lion section of the discussion.apple.com site. Here's what I did to fix this problem:

  1. Open Terminal.
  2. Open up a Finder window to a work folder.
  3. In the Finder menu bar, hold down Option and select Go->Library.
  4. Navigate to Saved Application State and open it.
  5. Duplicate the com.apple.Terminal.savedState folder (it will create com.apple.Terminal.savedState copy).
  6. Drag com.apple.Terminal.savedState copy to the work folder.
  7. In the work folder, rename that to com.apple.Terminal.savedState.
  8. Delete all the contents of com.apple.Terminal.savedState in the work folder. In other words, that com.apple.Terminal.savedState folder should now be empty.
  9. Go to Terminal and issue a Quit Terminal.
  10. Depending on your system settings, the com.apple.Terminal.savedState folder might now have disappeared from Library/Saved Application State. If so, that is good. If not, delete com.apple.Terminal.savedState from the Library/Saved Application State folder.
  11. Drag the empty com.apple.Terminal.savedState folder from the work folder to Library/Saved Application State.
  12. Do a Control-Click on this com.apple.Terminal.savedState folder, and select Get Info.
  13. In the Info window, select the Locked checkbox, then close the Info window.

Now, the Terminal application will not save its state on restart, nor at any other time.
.​
This worked initially. But yesterday, Terminal started opening at login again.
Operating System: OSX 10.7.2.

I checked and confirmed the following:
1) My com.apple.Terminal.savedState folder is empty and locked.
2) The Terminal app is NOT checked to 'Open at Login'
3) Preferences>General the 'Restore windows when quitting and re-opening apps" box is not checked.
4) Terminal Closed before shutting down.
5) Unchecked box to 'Reopen windows when logging back in.'

Any ideas on what changed? Any help would be appreciated. I seldom use Terminal so it is annoying when it loads.
 
This worked initially. But yesterday, Terminal started opening at login again.
Operating System: OSX 10.7.2.

I checked and confirmed the following:
1) My com.apple.Terminal.savedState folder is empty and locked.
2) The Terminal app is NOT checked to 'Open at Login'
3) Preferences>General the 'Restore windows when quitting and re-opening apps" box is not checked.
4) Terminal Closed before shutting down.
5) Unchecked box to 'Reopen windows when logging back in.'

Any ideas on what changed? Any help would be appreciated. I seldom use Terminal so it is annoying when it loads.
OK. This one I fixed, once again. This time the problem was that somehow a java script was added to my Preferences>Users & Groups>Login Items. The java script was opening up Terminal. Not sure why it got added or how, but I deleted the java script and all it well.

I received one response but the solution is not what I needed. I just didn't need Terminal to load.
Thanks
 
I have found Safari's reopen-last-used-windows "feature" to be rather useful because, since moving to Lion, about every three days Safari gets its knickers in a knot, with beach balls and alerts saying "Web pages not responding ...". I (force) quit, count to 3, and restart - after a few seconds, it's all back where I left it.

Does anyone else see this Safari behavior?
 
Back
Top