Absolute beginner's questions

Hello everybody,

This will be one of those “were do I begin?” posts, so please accept my apologies and just ignore this if you are not in the mood to respond.

I love Macs, used them in the mid-late 90s until I was forced to go Windows (the PPC 7500 and PowerBook 5300 running MacOS 8 were my last real Macs from that era). The last 15 years I did command line, registry, Winbatch and a little PowerShell. I did a little C# in Visual Studio, a little more Visual Basic. I wrote more or less complex web applications (mostly in classic ASP with vbscript and Oracle database integration) but most of the stuff I do is command line and WinBatch. Nothing even close to be object oriented. Nevertheless I built a pretty well working environment to manage more than 4000 Windows computers without SMS, SSCM or any of the other Microsoft or 3rd party products. I’m fluent in English and German, I’m not afraid of the registry or command line scripts but ASOC is really challenging me.

Three years ago I was asked to figure out how to deploy and manage modern Macs in an Enterprise environment. I got pretty good with bash shell scripting and Casper/JSS but it wasn’t what I really needed or wanted to do because it was missing a real UI, windows with multiple fields, checkboxes and such to gather input and then do what it needs to do. That wasn’t an issue because Macs are more a hobby to us (we have 8 Macs and 4000 Windows computers) but that may change sooner or later.

Fast forward to about 4 weeks ago, I decided to look seriously into creating an environment for the Macs like the one that we have for Windows. I remembered AppleScript on System 7 and MacOS 8 from he old days and after some research I ended up with AOSC as the ideal platform. Mostly top to bottom shell scripting “style” but with the advantage of adding some UI elements to gather data and process it accordingly.

I got Shane’s books and started reading and playing with the examples. I found more examples on how to program ASOC looking at “open source” apps like AutoCasperNBI and AutoDMG and managed to hack together my first 1000 lines of code in AOSC that do kind of what I expect it to do.

But I still don’t get the object oriented part of ASOC. I still have a hard time when I look at chapter 11 of of AppleScriptObjc Explored 5 and wonder how he got the orderFront: Sent Action linked to that panel window and button. I spend the last few weeks half of the day googleing keywords and got mostly stuff for Xcode 4 or 5 that doesn’t make much sense in Xcode 6 anymore. As usual, most of the time it’s about figuring out what t search for, what’s the right keyword that gets me one step further.

So, the bottom line and main question is: where do I start? What book do I get to get the real basics? Do I need to learn Objective C first and then do AOSC? Where are all those build-in methods listed (like on windowShouldClose_(sender) or on windowDidBecomeMain_(sender))?

Again, my apologies for asking such noob questions but I would really appreciate any hints or links or other recommendations on how to learn ASOC.

Thanks for reading,

I think what you’re asking is how do you learn to use the frameworks, and there’s no one simple answer to that. It generally involves trawling through the class references, and especially the associated guides (click More related items… in a class reference).

After that, it’s a case of looking for samples, and hitting Google. A good Cocoa programming book can help, but like my book, they can only scratch the surface. Each class can be a bit like learning how to script a new app – the sheer amount of stuff is what makes it so powerful and useful.

For your specific question, for windowShouldClose: look under NSWindowDelegate.

And of course you can always ask in places like this.

Thanks, Shane, I appreciate the reply.

I got frustrated yesterday because I couldn’t figure out how to open a close a window or panel. I looked at your Chapter 11 example and I see that the panel has two received actions, send from the buttons, but I couldn’t figure out how you got the orderFront and orderOut actions wired in there. This morning after a fresh start I figured that orderOut and orderFront are two actions visible in the Connections Inspector. So I wired them up and things started working. A little comment mentioning the Connections Inspector after saying “no code is needed” would have pointed me into the right direction and helped an absolute beginner like me a lot. I’m not complaining, your books are a great way to get started but as you said they can only scratch the surface.

Since I’m still very new to Xcode, I didn’t even realize that huge collection of documentation and references build in. I found the reference to windowShouldClose but there was no direct reference to ASOC, only Swift and ObjC. I guess that’s the missing link and important hint again and I suppose any ObjC method can be used in ASOC. Like adding “on windowDidMove:sender” to do something if the user moved the window. Does that only apply to NS classes or does it work with all he other classes also?

Thanks for the offer to ask here, I promise I will search first.


Pretty much. There are exceptions, but that’s the idea.

You can call stuff in other frameworks, as long as they’re Objective-C-based.

I think the hardest part is that that AppleScript has a different paradigm than Objective-C and therefore AppleScriptObjC codes has to written in a different style than normal vanilla AppleScript. One of the beauties of AppleScript-Studio was that it kept it’s paradigm and everyone who could write a script could write an application in AppleScript-Studio. Since Yosemite AppleScriptObjC can be written into normal script files but you have remember that it’s still a bridge between the Objective-C runtime and AppleScript and not vanilla AppleScript code that you write.

While Shane’s books are very verbose and discuss the important and basics aspects of Cocoa programming using AppleScriptObjC. To get a better grip of your “problem” I would advise to look more deeply what NSbundle and NSApplication actually is. What a process differs from an application for instance on your machine and all that kind of stuff. How an application, when initialized, connects to the desktop’s window server and how bundles serialize and unserialize nib objects (how objects from a file comes alive).

About the object oriented part. Keep in mind that object oriented is programming in the most efficient way (which is arguable) of programming and nothing else. At some level the code is is transformed into procedural code again where it requires an explicit runtime or virtual machine to make the object oriented features possible. Object oriented programming is in some sort of way a false presentation of what really happens, on the other hand to write object oriented code you have to think object oriented. An Objective-C object is nothing more than a c-struct. Methods are in fact just functions where the c-struct is send to each function as the first parameter. Messaging is done using the runtime and a lookup in a hash table, no results writes a log in the console that the method not exists instead of an segmentation error crashing your application or even worse causing a kernel panic instead of a direct function call. Properties are nothing more than another set of functions (getters and setters). You get a very script like feeling for a compiled language but of course at some costs.

There will never be a direct reference to ASObjC. Bridges are normally never considered as an genuine programming language, it’s using the paradigm of one of the two existing languages, in this case Objective-C.