An Introduction to AppleScript on Mac OS X
Subject:   Wanted: AppleScript sans ObjC info
Date:   2002-01-04 20:45:52
From:   benjk
Response to: Wanted: AppleScript sans ObjC info

AppleScript Studio should be what you are looking for. Go to Apple's developer site and download the latest developer update which includes AppleScript Studio; then follow the documentation and tutorial.

It's all very straightforward and should get you started very easily.

However, don't make the mistake to compare AS to VB. If you try to think in VB while trying to write code in AS, you will probably get frustrated very soon.

If you want to get the most out of AS, you probably want to get familiar with the underlying concepts and use them to your advantage and not try to work against them, as I did.

VB is a procedural language which got many of its constructs and concepts from Pascal.

AppleScript is not a procedural language and it doesn't employ strict data typing ala Pascal. Instead, AS shares its paradigms with languages such as Lisp and Scheme.

I tend to think that when learning AS, a newbie without any programming experience may have various advantages. Those of us who grew up with K&R or N.Wirth programming paradigms have to get rid of some ballast first.

One example is coersion, the ability to dynamically adjust the type of a variable at runtime. This is not at all like type casting and it almost drove me nuts when I started to do a bit more with AS than just "Hello World". I was always trying to build code from scratch where one simple AS construct would have done the whole thing for me.

In fact, the more I got involved in AS, the more it reminded me of the little I remembered about Lisp, a language I had visited a course for a long time ago at university and which had both puzzled and fascinated me because of the incredible things one could do with it employing only very little code if only one knew how to work it.

I have come to think of AppleScript as a kind of defused Lisp for the rest of us.

While AS is in principle easy to get started with, it is important to be able to handle the underlying paradigm shift in order to master it.

As far as Objective C and Cocoa Frameworks are concerned, you don;t need to know much when using AppleScript Studio. It does however do no harm if you get to know a bit more about Cocoa Frameworks as you go along.

The Cocoa Frameworks are to AS Studio what you called "a bunch of widgets" to your VB environment. The beauty of AS Studio is that it allows you to use these tools without the need to write code in Objective C as you would otherwise have to do.

One more thing which makes AppleScript different from most other scripting languages is the way it is integrated into the OS's event management. This is even more true with OSX and Cocoa than it was under the legacy MacOS.

In a way, AppleScript allows you to tap into the OS's event management so as to mimic user actions to the OS and its applications. Where other scripting architectures need to use a secondary service entrance into the applications, AppleScript with Cocoa allows you to fool the application that the user came through the front door, thus being able to script anything that could be done using the GUI.

This means a potential for any application under OSX to get a standard API almost "by accident" instead of "by sweat". As the article explained, it used to be hard work for application developers to build this into their apps and now with Cocoa it almost comes as a side effect. This is a good thing and it is not confined to AppleScript, the language, but a feature of OSA, the underlying architecture and the way it has been integrated into Coca.

Theoretically, one could make VB to link into OSA, to become a scripting language from which to tap into the event management just like AppleScript does already.

I understand that ECMAscript (standardised version of JavaScript) is available already as an alternative scripting language for OSA. So, as you can see, the syntax is pretty much interchangeable, but the power comes from the underlying architecture.