0
Dalibor Sliva 1 week ago • updated by Alexander Blach (Developer) 6 days ago 8

I'm using Textastic from the begining and I like it a lot, I appreciate your work. But it would be nice to add an option "don't close application when last window is closed", because it's more Mac OS standard behaviour what some applications does not respect including Textastic and personally it's annoying in some use case. Can you please do that? Thanks

Actually, Textastic tries to use macOS standard behavior as much as possible. What you are seeing is called "Automatic Termination". It was introduced in macOS 10.7 Lion. If you close the last window and then switch away from the app, the app is closed automatically.


This is a snippet from the developer documentation:


Automatic and Sudden Termination of Apps Improve the User Experience

In OS X v10.7 and later, the use of the Quit command to terminate an app is diminished in favor of more user-centric techniques. Specifically, Cocoa supports two techniques that make the termination of an app transparent and fast:


  • Automatic termination eliminates the need for users to quit an app. Instead, the system manages app termination transparently behind the scenes, terminating apps that are not in use to reclaim needed resources such as memory.
  • Sudden termination allows the system to kill an app’s process immediately without waiting for it to perform any final actions. The system uses this technique to improve the speed of operations such as logging out of, restarting, or shutting down the computer.

Automatic termination and sudden termination are independent techniques, although both are designed to improve the user experience of app termination. Although Apple recommends that apps support both, an app can support one technique and not the other. Apps that support both techniques can be terminated by the system without the app being involved at all. On the other hand, if an app supports sudden termination but not automatic termination, then it must be sent a Quit event, which it needs to process without displaying any user interface dialogs.

Automatic termination transfers the job of managing processes from the user to the system, which is better equipped to handle the job. Users do not need to manage processes manually anyway. All they really need is to run apps and have those apps available when they need them. Automatic termination makes that possible while ensuring that system performance is not adversely affected.

Apps must opt in to both automatic termination and sudden termination and implement appropriate support for them. In both cases, the app must ensure that any user data is saved well before termination can happen. And because the user does not quit an autoterminable app, such an app should also save the state of its user interface using the built-in Cocoa support. Saving and restoring the interface state provides the user with a sense of continuity between app launches.

For information on how to support for automatic termination in your app, see Automatic Termination. For information on how to support sudden termination, see Sudden Termination.



https://developer.apple.com/library/content/documentation/General/Conceptual/MOSXAppProgrammingGuide/CoreAppDesign/CoreAppDesign.html

You can disable Automatic Termination system-wide using the command line:


Disable Automatic Termination in Mac OS X
Launch Terminal and enter the following defaults write command:

defaults write -g NSDisableAutomaticTermination -bool yes

Re-Enable Automatic App Termination in Mac OS X
You can always reenable the default behavior of OS X and turn auto termination back on:

defaults delete NSDisableAutomaticTermination

I copied the instructions from this article: http://osxdaily.com/2012/05/15/disable-automatic-termination-of-apps-in-mac-os-x/

Thank you for your answer, it's been very helpful. I'm not an developer, I didn't know about that and sorry for my suspicion you don't follow the standards. Unfortunately, Apple start bringing a lot of mess with OS X 10.7 and newer releases, so no surprise for me actually. The result is, that every application handle it different way, so it makes Mac OS behavior less consistent, thats all what Apple has achieved in my opinion. It worked good for years and they just messed it up, sadly (like many other UI-inconsistency things with open/save dialogues and many more I can see at these days). I'm a long time Mac user and I never ever had any problem with application without dialogues, because of menu bar where everybody can see what application is active... but Apple decided to "fix" what don't need to be fixed and bring the mess to the stage. At least that "Automatic termination" can be disable syste-wide and I'll definitely try it.


Just let me know, please, why you decided to use Automatic termination instead of Sudden termination, because Textastic is actually very subtle application, it doesn't consume a lot of system resources. I can understand, when Automatic termination is used for some memory heavy "bloatware", which are typicaly used for an hours and then closed, but I simply can't see any benefits to use it with Textastic.
Textastic isn't just "all-day-long coding" application which I open at the morning and quit at the evening. It's also a handy tool. For example, when I'm opening and closing source files from FTP (for quick editing), I actually open and quit whole Textastic XY times per minute for no actual reason, just because of Automatic termination. I'm not telling it's a big problem when we have a fast SSD's and Textastic starts quickly, but it makes no sense to me.
And one more thing, I know about applications which have an option like "quit application when last window is closed". This is actually why I asked for it in my original post. So how they can handle this, when, If I understand well, you're saying it's impossible use both termination techniques? Maybe it's something like unofficial "hack"?
Many thanks to you again,
Have a nice day,
Dalibor

Apple recommends that apps support both Automatic Termination and Sudden Termination. That's what Textastic does.


Other apps probably do not use the official system mechanism for closing the app when the last window is closed but use a custom solution/hack.


With Textastic I try to follow Apple's best practices as much as possible.

OK, I understand. I read your tip from OS X Daily and I try to disable Automatic termination for Textastic exclusively (instead of system wide) with this command modification:


defaults write com.textasticapp.textastic-mac NSDisableAutomaticTermination -bool yes


It works like charm and it don't terminate whole application like maniac every time I close document. Many thanks for this tip!


Sadly, when I hit the Textastic icon in the dock (and application has no window open), it shows me that unnecessarily annoying "open dialog". When I want just make application active, It would be nice make it active and don't perform any useless actions I don't want and I don't care about, just because Apple think it's good for me. But that is an another inconsistent mess Apple bring up with 10.7, and I know, it's "today standard", unfortunatelly.


You can change that behavior, too: if you want that Textastic opens a new untitled file instead of the open dialog, you can use this command:


defaults write com.textasticapp.textastic-mac NSShowAppCentricOpenPanelInsteadOfUntitledFile -bool false

Thanks for your assistance Alexander, I appreciate it. It's nice tip, but I would like just make Textastic active without performing any other actions (open dialog, new file or anything else). Is that possible?


Anyway, I can make Textastic active with CMD+TAB, when I use this, Textastic just became active without performing any other action.

I don't think you can disable it when click on the Dock icon. Yes, with Cmd-Tab it works.