AppleScriptObjC in Xcode Part 1

By the way, in your final code, am I right in saying you don’t need the line:

property aTableView : missing value

That is correct. I will update the tutorial and the source code. Thanks for catching that!

@Craig
Hi, I got only one blue cube (it´s a controller?) but it doesn´t react when I control drag from the button.

OK, I think I got it.
My project is named ‘secondTry’.
Unfortunately I copied the code from your example and that is called ‘PartOne’ and in the first line of my project I had PartOneDelegate.
After I changed it to the correct name it worked.

Thanks for this example.

Greetings, Ronald

One mor question please.

the to lines (are they still Handlers?)

on applicationWillFinishLaunching_(aNotification)
      and
on applicationShouldTerminate_(sender)

where are they from? Are they user defined? Looks like since I don´t find them in the Doc.

Greetings, Ronald

some more remarks:

I wondered why
textField’s setStringValue_(“Default text”)

didn´t work inside awakeFromNib()

But it does work when I commet this line out
textView’s setTextContainerInset_({10.0, 10.0})

Debugging is not working, any clues?

Greetings, Ronald

You can find them in the documentation under “NSApplicationDelegate Protocol Reference.”

They are handlers but you do not call them directly, they get called automatically by your application.

Things to try.

  1. Reversing the order. Put setStringValue before textView.
  2. Make sure textView is hooked up inside interface builder. If you are having trouble understanding how to hook things up watch the video on GUI building in Part 2.

Debugging is not working I know. The way I debug is with “log” and “try” statements in my code.
Also, try to focus on getting one thing working at a time and build from there.

Do you have the “Console” open in Xcode when you “Build and Run?” There are error messages there that help in debugging as well.

eg.


log "Setting default value in textField"
textField's setStringValue_("Default text")

log "Setting inset in textView"
try
  textView's setTextContainerInset_({10.0, 10.0})
on error e
  log "Error setting inset: " & e
end try

hth,

Craig Williams

Hi Craig,
thanks a lot for your explanations.
Well I´ve already done some Objective-C this year and are pretty familiar with connecting elements to the controllers.
I´ll give it one more critical look :wink:

I think ASS-OBJC is really thrilling.

Greetings, Ronald

Hi Ronald,

I have noticed that I have to do a “Clean All” more than I would in an Objective-C project.
Maybe doing that will help.

Regards,

Craig

I just read a few topics here today because I was very thrown off by the new Xcode and the changes in Applescript under OS X.6.

I ran into this topic and I will be looking at it thoroughly, and hopefully this will get me started with ApplescriptObjC (which really freaked me out for a second there, going “how the hell am I going to get into that!”).

Thank you Craig, thank you for your work and your contribution.

BS0D

Hi BSOD,

Thank you for the kind words.

I know this is a big change for everyone. I think learning some Objective-C will help in getting the most out of AppleScriptObjC. I mean, just look at the name. Objective-C is part of the name.

I have listed out a few resources for learning Objective-C here.

I believe with just a small amount of Objective-C understanding, writing applications in AppleScriptObjC will be much easier.

Regards,

Craig Williams

Thank you for the link, anything I can gather will most likely be useful.

Yes, when you know where to start !

I’m still very afraid that I’ll be totally incapable to develop any useful, meaningful applications now.
I was thinking of rewriting my first ASS application in ApplescritpObjC but surely it will take some time for me to be able to do that : all the resources I’ve found and looked at so far have confused the hell out of me.

Haven’t looked at part 2 yet, but ALREADY I wonder : how about when there are 3 or 4 textFields on the same window ? How would you make sure you refer to the right one in the code ?
Don’t you have to name them or define them like you would in ASS ?

How would that work ?

I CANNOT WAIT TO LEARN MORE. Despite the difficulty of learning, if not a new programming language, at least its basics, it looks really awesome!

Every object in your window needs a reference to a property in your AppleScript file. Each text field will have its own property. You link the two together in Interface Builder by control dragging from the Application Instance (*blue cube) to the text field and clicking on the corresponding property. Watch the GUI building video from Part 2 for a demonstration on how to do this.

I am currently working on a tutorial to demonstrate how to lookup Objective-C methods in the documentation, understand what you are seeing there and how to convert that to AppleScriptObjC.

“A journey of a thousand miles begins with a single step” - Lao-tzu

I know it is hard learning new languages. It is hard for all of us. You just have to begin. I started by reading Aaron Hillegass’ book. I must have read the first 100 pages at least five times before it started sinking in. I went to the Big Nerd Ranch for a week of training. I spent hours each day going through tutorials, writing code, reading, experimenting, etc. I wrote lots of “throw-away” programs just for the sake of learning.

I did pretty much the same thing to learn FileMaker Pro, AppleScript, HTML, JavaScript, PHP, Ruby, you get the idea. I invest time, money and energy into the process and after a period of time it pays off.

Give yourself time. You can do this!

Regards,

Craig

*blue cube

.
.
.

Yeah, sure it takes time. You know how it is though, pretty much everyone I know who wanted to learn programming also wanted to know it all in a day and be able to code actual applications in no time.
I can’t wait for more of your tutorials, they make me a bit more enthusiastic about this whole change in Applescript programming!

(However, Part 2 is waaay too vague for me, after reading 3 times I’m still not getting all of it – in comparison to part 1 you seem to assume that all your readers have gotten the hang of Objective-C classes etc which is def not the case!)

I struggle more with writing than I do with coding. :slight_smile:

Is there any part that is particularly vague or is the whole thing difficult to understand?
I don’t mind re-writing or going into more detail but I would like to work on the areas that
are the most difficult to grasp.

I know exactly what you mean, when something is “natural” to you, it’s difficult to put yourself back in a position where everything is new, where you’re just discovering.
It’s nothing personal and I hope I didn’t offend you – sorry for the way I wrote that. Don’t get me wrong, you’re doing an amazing job here, and needless to say you are a pioneer at this right now.

Well for one thing, my C experience dates back to a few years and I’ve forgotten it all. “Classes”, “Parent classes”, etc… English not being my native language, are confusing terms as I cannot remember exactly what they are, and what we need them for.
I guess it’s nothing in particular, just the whole thing is a little blurry to me.

I guess because the comments seem less clear than explaining exactly what you’re about to do, what you need to refer to and THEN showing the code for it, like you did in tutorial 1. Am I making any sense ?
Oh, a few confusing bits to me so far : what’s the difference between Cocoa and Objective-C ? Ojb-C is a programming language, so what about Cocoa ? is it a framework or does it have something to do more with the GUI side of programming ? I see both these terms used in documentation, seems like one could be used instead of the other sometimes…

I am not offended in the least. I appreciate the feedback and want to make these articles as understandable and user friendly as possible.
If they are not, I want to correct that.

The best place to start is “Introduction to The Objective-C 2.0 Programming Language.

Complete sense. Once I get through with the tutorial I am working on I will go back and make the necessary adjustments.

I found a great explanation here.
.
.
.

okay, so I follow along with the very first part, draw my connections as instructed to do in Interface Builder, and…nothing. type in the text field, click the button, nothing happens. When I look at the downloaded project, I noticed that in the downloaded project, the textView field has neither a referencing outlet or a nextKeyView, whereas in my project, it does have a referencing outlet. The text field in your project has both a nextKeyView and a referencing outlet, whereas my version has neither.

I copied the code out of the example, so I’m pretty sure I don’t have a typo, but I think there’s a step or two I’m missing. Ideas?

Zip it up and email to craigw@macscripter.net.

Thanks for the help craig, i’d have never guessed about the differences in the drag targeting.

Oh, one thing. in the initial part of setting up awake from nib you have the border and default text code as:

myTextView’s setTextContainerInset_({10.0, 10.0})
myTextField’s setStringValue_(“Default text”)

if you don’t initially notice that the ‘my’ shouldn’t be there, you can have a couple minutes of da head scratchin’