4

I have a java app that automatically launches when the machine boots. The trouble is that when Terminal is shut down, it does not actually close the window for that app, and so the next time the machine boots the old window is still there, and a new one is created when the app launches. So I get an additional tab/window every single day, forever.

System Preferences is already set to close windows when quitting an app. How can I get Terminal to stop doing this and actually close its tabs/windows when it is quit?

4
  • How does the Java application relate to Terminal?
    – nohillside
    Commented Sep 10, 2021 at 15:32
  • It doesn't per se, just wanted to include the detail in case it could somehow be relevant. Main point is that a terminal window is opened at startup and something is done.
    – JVC
    Commented Sep 10, 2021 at 15:33
  • I'm a bit confused now: You have a Java application which gets launched on login, opens an application window, and also opens a Terminal window? And if you reboot, you get the Java application, it's window and a second Terminal window?
    – nohillside
    Commented Sep 10, 2021 at 15:36
  • The application has no window. It just opens up a network listener (it's a local network streamer) and the terminal window sits there.
    – JVC
    Commented Sep 10, 2021 at 15:37

1 Answer 1

3

One way which won't interfere with any other apps is to clear the contents of the Saved Application State and set the folder to immutable.

Paste this into the Terminal

terminalSAS="$HOME/Library/Saved Application State/com.apple.Terminal.savedState"
[[ -d "$terminalSAS" ]] &&
rm -rf "$terminalSAS" &&
mkdir -p "$terminalSAS" &&
chflags -R uchg "$terminalSAS"

And to revert:

terminalSAS="$HOME/Library/Saved Application State/com.apple.Terminal.savedState"
chflags -R nouchg "$terminalSAS"

Breakdown


#this sets a variable for the folder of Terminal's Window data
terminalSAS="$HOME/Library/Saved Application State/com.apple.Terminal.savedState"

#check that the folder exists
[[ -d "$terminalSAS" ]] &&

#deletes the folder to clear saved window data
rm -rf "$terminalSAS" &&

#re-create blank folder
mkdir -p "$terminalSAS" &&

#set the folder to immutable (like the lock checkbox in Finder -> Get Info)
chflags -R uchg "$terminalSAS"
11
  • Wow... I completely don't understand that. Feels a bit heavy-handed... =/
    – JVC
    Commented Sep 10, 2021 at 15:34
  • @JVC open up Terminal and paste the whole block in there and press Enter
    – hmedia1
    Commented Sep 10, 2021 at 15:36
  • 1
    No I understand how to use it. I don't understand what it does, and I don't generally like executing code I completely don't understand the function/purpose of.
    – JVC
    Commented Sep 10, 2021 at 15:36
  • 1
    @JVC I'll write explanatory comments..
    – hmedia1
    Commented Sep 10, 2021 at 15:37
  • 1
    Looks to be invalid syntax, gave me a man page. (it did not exist so I tried to write it)
    – JVC
    Commented Sep 10, 2021 at 19:45

You must log in to answer this question.

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