Quit Handler in Xcode ??

Hi Everyone

I am trying to learn ApplescriptObjC in Xcode.
[I have several “FaceSpan” projects to update.]

Working my way thru Shane Stanley’s "AppleScriptObjC Explored Fifth Edition.
Just got "Step into Xcode by Fritz Anderson and
“Cocoa Programming for Mac OSX” by Aaron Hillegass.

I am pretty proficient with AppleScript but not so much with Objective C.

When Xcode creates a project there is an included handler:
on applicationShouldTerminate:sender -------------> “Quit” Button
– Insert code here to do any housekeeping before your application quits
return current application’s NSTerminateNow
end applicationShouldTerminate:

I have linked this to a “Quit” button on my interface but nothing happens when I push the button.
After inserting a “display dialog” in the handler to see if it works and the dialog appear when I push the button so I am pretty sure the handler is being triggered.

What am I missing here?

Thanks – my head hurts :slight_smile:
Oakley

Model: 10.9.5 OSX on new iMac
AppleScript: Script DeBugger 5.0.9
Browser: Safari 537.85.10
Operating System: Mac OS X (10.8)

Hi,

on applicationShouldTerminate:sender is a delegate method of NSApplication and is called before the application is going to quit. The method should not be connected to any UI element.
It expects a enumerated return value of type NSApplicationTerminateReply

From the documentation:
Allowable return values are:
NSTerminateNow - it is ok to proceed with termination
NSTerminateCancel - the application should not be terminated
NSTerminateLater - it may be ok to proceed with termination later. The application must call -replyToApplicationShouldTerminate: with YES or NO once the answer is known
this return value is for delegates who need to provide document modal alerts (sheets) in order to decide whether to quit.

Connect your button to FirstResponder > terminate:

THANK YOU StefanK.

I appreciate your reply and helping me understand the process.

so - Do NOT connect the “Quit” button to the “on applicationShouldTerminate:sender” handler…

Got It.

Connect it to: FirstResponder > terminate:

Ok, here is the problem - When I said that I was not so good with ObjectiveC what I should have said is that I am a total beginner and only barely started. I looked up FirstResponder and read about it but do not know how to access it in my script.

Do I create a property firstResponder : missing value ?
Do I create a handler ?

truthfully I am lost here.

Thanks again
Oakley

In Interface Builder instead of linking the button to AppDelegate (or whatever the name of your application delegate script is) > applicationShouldTerminate control-drag the button to the First Responder red cube and choose terminate:

First Responder methods are methods which are sent to the responder chain instead of a specific target.

OMG that is SOoooooo Kool !!!

Thank you StefanK for your help with this. Everything is always easy after you know how. :slight_smile:

That is the first time I have ever looked at the “First Responder” icon. So many option choices available.

Wow - all the way from Switzerland.
It really is a small world.

Thank you Again.
Oakley