Force the currently focused field to end editing?

Hey there. in my AppleScript Studio application i am making, a person can fill in text fields with info. when the end editing event of the fields are triggered, the info is fed into a table view.
when a person is done entering fields and is ready to process the files, they click a go button.
the problem i am having is this:
is the user is currently editing a field when they click the go button, the end editing event is never triggered. how do I force any fields currently being editing to end editing, so my table data can be updated, so the files get processed with all the data, and not missing the info from that final field?

You can call -[NSCell endEditing:] on the text field’s cell and pass the current editor of the field. Example:

[[yourTextField cell] endEditing:[yourTextField currentEditor]];

It probably looks something like this in AppleScript (untested, may be wrong):

call method "endEditing:" of (call method "cell" of text field "blah" of window "main") with parameter (call method "currentEditor" of text field "blah" of window "main")

There may be a Studio way of doing it, but I’m unfamiliar with it.

Ill give that a try, but that will only solve half the problem if it works. there are multiple fields, so I need to somehow find out what field is in focus so i can send the end edit command.

Have you read any documentation to find out how to do this yet?

Ive looked through plenty of poorly worded and vague documentation, yes, as well as plenty of googling to try to find the answer. Im not one of those people who dont do research or don’t RTFM prior to posting a question.

And to Jaques: thank you for your help.

Poorly worded? Vague? What were you reading? Perhaps we can help refine your searches a bit.

Well lets see here. in xcode, if i open up the applescriptkit.sdef file, and look up, first responder, for example, this is the result

Wow. that sure tells me a hell of a lot. At least I know it belongs to a window now. Lets look up responder then…

Again, no help there at all. Let see… how about “text color” for a text field:

now color:

wow. what rocket science. I could have never figured that much out myself without trekking across the nine circles of hell and selling my soul to the devil himself. No where does it mention what format a color is in. is it simply “white”, “black”, etc? or is it hex value #FFFFFF, or is it rgb: 255, 162, 0?

Perhaps its just that Im newer to applescript language and the terminology Im used to is different. Perhaps the definitions should be updated. To me, Im used to an item having “focus” to represent that the item is active and receiving input, or is frontmost, etc. Looking up focus in the definitions list, I get “lock focus” and “unlock focus” neither of which do what I was trying to accomplish. So, perhaps poorly worded and vague are not quite the words I was looking for; perhaps the definitions were written in such haste that the writer simply assumed you already knew what everything already did and was writing them simply for the sake of having something written for them. Oh wait. I guess poorly worded and vague were exactly the terms I was looking for. Considering Ive only been programming in Applescript studio for a week, its amazing Ive managed to get as far as I have without a really good book by my side (for which I have, and am still looking for, preferably something that is for both applescript and xcode/IB… and… heres the kicker… up to date.)

So, one more quick question:

Why the attitude? I wasn’t being sarcastic when I said we might be able to help refine how you use the documentation. And if you get offended at someone asking if you’ve read the documentation, you’re really going to hate being a developer.

If you’re interested, -lockFocus is called on a view when you’re about to draw into or read out of the current graphics context of the view. -unlockFocus returns to the previous graphics context. It doesn’t only apply to views, though, because NSImage has the same methods, used for locking onto the context of an image and drawing into it. (Say, if you wanted to draw some nice shadowed text onto an existing image, you could load the image into memory with NSImage and draw into it after locking focus onto it.)

Search developer.apple.com for Cocoa articles relating to the responder chain and how views gain and relenquish their first responder status. There are some things you should know about NSResponders[1] and how NSWindows interact with responders. Learning how Cocoa works (especially views) will help you understand AppleScript Studio. ESPECIALLY the Studio documentation, which is, as you’ve found, anemic at times.

[1] Notice that NSTextField’s class hierarchy looks like this:

NSTextField : NSControl : NSView : NSResponder : NSObject

That is, NSTextField descends from NSResponder.

Sorry about the attitude. It was a rough day, and it felt like i was being given the standard RTFM response that people frequently give to newbies who, frequently dont RTFM. However, I am one who will often spend hours or days looking for an answer before finally posting a question; and a response of RTFM when the manual is obvious junk really just rubbed me the completely wrong way.