Key equivalents, textfield help :(

I am new to AppleScript ObjC, I only briefly got my feet wet with Applescript Studio. I have however worked with applescript for almost a year. After reading through all of the tutorials posted up I still have some questions that I would really appreciate help with. I am sure that they are simple questions but I still haven’t been able to find the answers by reading the other threads in this forum. It seems most users on this forum are working on far more advanced projects than me.

Question #1

In applescript studio I was able to set key equivalents by running the following code:


on keyboard up theObject event theEvent
           set key equivalent of button "myButton" of window "myWindow" to return
end keyboard up

I haven’t been able to figure this out yet in Applescript ObjC. :frowning:

Question #2

This is another easy one that I feel slightly embarrassed about asking. I have searched and looked at the examples and still don’t get it. (All of the examples in the tutorials show the textfield changing as the result of a button being pressed) I am trying to set the content of a text field on the launch of the application. In Applescript Studio, I would attach a line or two in the awake on nib section as follows:


on awake from nib theObject
	set contents of text field "myTextfield" of window "myWindow" to "Whatever content I want"
end awake from nib

I have been able to learn that awake from nib has changed to:


on awakeFromNib()
------Magic code that makes this work!	
end awakeFromNib

I have tried sticking in


"set myTextfield's content to "Whatever content I want"

This is not working since I must be missing something important. The information I am looking to put into the textfield will not be static it will be different each time the application is launched.

Can someone shed some light on these for me? I would really appreciate it.

Sincerely,
Confused

First, to refer to a text frame or button, you need to have a reference to it. You do this by defining s property, set to missing value, and then you make the connection in Interface Builder. You can see how to do this in the movies available here http://allancraig.net/blog/?p=639 and http://www.macosxautomation.com/applescript/develop/.

Then the code becomes:

 theButton's setKeyEquivalent_("\r")

and

 theTextField's setStringValue_("Whatever")

It’s quite different to ASStudio; you should have a look at the tutorials Craig Williams has posted elsewhere on macscripter.net.

Here is some tips:

#1

property theobject : missing value -- it shows up in IB

on action_(sender)
theobject's OBmethod_("text")
end

Anything like “content” that compiles into a color that’s not green is probably not correct Applescript Objective-C code. “theobject’s content” is incorrect because “content” is a violet color. Most of the time, it is around pipes, like “|color|.”

#2
A correct line world be

set hello to textfield's stringValue() as string

or

textfield's setStringValue("Text goes in here")

#3
Interface Builder has a lot of functions that take away a lot of code.

Thank you guys for helping me out on this one. I really appreciate it. Now I have finally stopped banging my head against the desk on this one. I ended up putting both of them into the awake from nib like this and it works fine.


on awakeFromNib()		
		theButtonA's setKeyEquivalent_(return)
		theButtonB's setKeyEquivalent_("b")
		theButtonC's setKeyEquivalent_("c")
		theButtonD's setKeyEquivalent_("d")
		theButtonE's setKeyEquivalent_("e")
		theCheck's setIntValue_([0])
		theField's setStringValue_("my content")
	end awakeFromNib

I did however notice that the key equivalent for return wouldn’t work as “\r”, return works fine though.

Thanks again! :slight_smile: