Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Can I make the red button quit the app?

Can I make the red button quit the app?
Thread Tools
macbuddha1
Fresh-Faced Recruit
Join Date: Mar 2003
Location: California
Status: Offline
Reply With Quote
Apr 22, 2003, 09:26 PM
 
OK dev people...
Others have told me that it might be very easy to make an application quit when you click the red "x" button, instead of just closing the window, however I just don't have the know-how. This would be very helpful to me as a teacher, where many of my students tend to close windows but not actually "quit" apps, as they seem to be used to doing on Windoze. I know, I know, Apple + Q, but hey, humor me...

Anyone ever try this?

Thanks for looking!
All Mac since 1987.
www.mactechedu.com
     
Rickster
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Apr 22, 2003, 10:25 PM
 
See the class documentation for NSApplication's delegate methods. (If you're writing a Cocoa app.)
Rick Roe
icons.cx | weblog
     
MrBS
Grizzled Veteran
Join Date: Jun 2001
Location: Seattle
Status: Offline
Reply With Quote
Apr 23, 2003, 01:02 AM
 
Originally posted by macbuddha1:
OK dev people...
Others have told me that it might be very easy to make an application quit when you click the red "x" button, instead of just closing the window, however I just don't have the know-how. This would be very helpful to me as a teacher, where many of my students tend to close windows but not actually "quit" apps, as they seem to be used to doing on Windoze. I know, I know, Apple + Q, but hey, humor me...

Anyone ever try this?

Thanks for looking!
You probably want to ask in the os x forum, unless you're writing your own applications.

If you don't find an answer take solace in the fact that leaving multiple apps open won't hurt performance much at all, the only real problem you'll have is dock clutter.

~BS
     
Gul Banana
Mac Elite
Join Date: May 2002
Status: Offline
Reply With Quote
Apr 23, 2003, 04:30 AM
 
You realise, of course, that if you do this, many of the people who use your application will feel a burning desire to hunt you down and slaughter your entire family?
[vash:~] banana% killall killall
Terminated
     
aleph_null
Dedicated MacNNer
Join Date: Jan 2001
Location: Boulder, CO, USA
Status: Offline
Reply With Quote
Apr 23, 2003, 12:55 PM
 
if you mean "is there a way to make the close button on Explorer or TextEdit or what-have-you quit the app?" then the answer is no. at least ... uh, not without some massively weird hack using unpublished APIs and probably more work than it's worth. those apps have been written, they do what they do, there's most likely no way to change them.

what would be pretty straightforward would be to make a big ol' red button in an app by itself that, when clicked, would quit all the usual apps your kids use. or ... a button that logs out.

if you mean "i'm writing this program and i want the close button to quit the app" then yeah ... that should be pretty easy.
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Apr 23, 2003, 01:25 PM
 
Actually, isn't this precisely the sort of thing APE was designed for?
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
smeger
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Apr 23, 2003, 02:34 PM
 
First off, I think that macbuddha1 is looking for someone to write him some code that will result in current applications changing their behaviour to "quit on window close".

It's do-able, but not easily (or nicely). One could write an APE module that would do it.

But, why? Users who know what they're doing would hate it. And there just isn't much need. In a well-written app, when you close the last window, that app uses zero processor time and swaps out the memory it used to disk. You can leave it running indefinitely with no adverse effects beyond growing your memory disk swap a bit. Unless you're running with only 64 MB or RAM or have only a few hundred megs of free disk space, don't worry about it.

Caveat - I said "a well-written app". There are still a few oldskewl apps out there that are "polling" for events. They will take some CPU time even when idle, but it's not a lot of CPU time.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
Colonel_Panic
Junior Member
Join Date: Aug 2002
Location: 127.0.0.1
Status: Offline
Reply With Quote
Apr 23, 2003, 03:32 PM
 
You realise, of course, that if you do this, many of the people who use your application will feel a burning desire to hunt you down and slaughter your entire family?
Yeah and if some one else already got to your family I`ll go for distant relatives
     
Diggory Laycock
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Apr 23, 2003, 04:23 PM
 
NSApplication has a delegate method:

applicationShouldTerminateAfterLastWindowClosed:

that does what you want.

Make your app controller object the delegate of NSApplication and implement the method mentioned above to return yes.
     
bousozoku
Forum Regular
Join Date: May 2001
Location: Oviedo, Floriduh USA
Status: Offline
Reply With Quote
Apr 23, 2003, 07:13 PM
 
Originally posted by aleph_null:
if you mean "is there a way to make the close button on Explorer or TextEdit or what-have-you quit the app?" then the answer is no. at least ... uh, not without some massively weird hack using unpublished APIs and probably more work than it's worth. those apps have been written, they do what they do, there's most likely no way to change them.

what would be pretty straightforward would be to make a big ol' red button in an app by itself that, when clicked, would quit all the usual apps your kids use. or ... a button that logs out.

if you mean "i'm writing this program and i want the close button to quit the app" then yeah ... that should be pretty easy.
It seems to me that there was an application which monitored the system event queue for the last window closed for any application you chose on Mac OS 9.x.

Carbon events and Cocoa events don't work this way though.
folding@home is good for you.
     
aleph_null
Dedicated MacNNer
Join Date: Jan 2001
Location: Boulder, CO, USA
Status: Offline
Reply With Quote
Apr 23, 2003, 10:23 PM
 
Originally posted by bousozoku:
It seems to me that there was an application which monitored the system event queue for the last window closed for any application you chose on Mac OS 9.x.

Carbon events and Cocoa events don't work this way though.
yeah. i was thinking of Quartz Debug. it has a list of every window managed by the window server and their owning processes. clearly there's *some* way to get that list. the calls are probably in the libs, just not published in the headers.

then, yeah: write a little app that polls the list and sends a quit apple event when all of an app's windows are closed.

hmm ... come to think of it, though ... a closed window is not necessarily a disposed window. guess you'd have to check for the hidden flag, too.

perhaps the best thing to do, in this situation, though, is to write a little app that checks the user idle time. after a while, it asks the Finder (or Launch Services?) to please log out the user, who apparently left the desk with everything running.
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Apr 23, 2003, 11:38 PM
 
then, yeah: write a little app that polls the list and sends a quit apple event when all of an app's windows are closed.
Er...I think that's about 500 times worse than an APE.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
coolmacdude
Senior User
Join Date: Feb 2003
Location: Atlanta
Status: Offline
Reply With Quote
Apr 24, 2003, 03:05 AM
 
Originally posted by Diggory Laycock:
NSApplication has a delegate method:

applicationShouldTerminateAfterLastWindowClosed:

that does what you want.

Make your app controller object the delegate of NSApplication and implement the method mentioned above to return yes.
STOP IT! Do you actually want this poor guy's family to die?
     
aleph_null
Dedicated MacNNer
Join Date: Jan 2001
Location: Boulder, CO, USA
Status: Offline
Reply With Quote
Apr 24, 2003, 02:51 PM
 
Originally posted by Chuckit:
Er...I think that's about 500 times worse than an APE.
yeah, particularly when it hasn't had its morning banana!


sorry: what's an APE?
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 08:47 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,