advertisement

Article:
  An Introduction to AppleScript on Mac OS X
Subject:   Dear Santa,
Date:   2001-12-20 01:38:56
From:   bdominy
Response to: Dear Santa,

Hi Pete,
Thanks for taking a look at this series. I'll try to address your three questions as best I can.


1. How to decide which approach is best using AppleScript?


This has always been a tough question, since there are so many problems to be solved and usually, as you say, many ways to go about solving them. This is true in AppleScript as it is any any programming language. I can tell you my way of thinking with regards to AppleScript is to come up with a work flow for the script to be written, first. This lists the apps that are needed and the info needed at each point to go on to the next point. Then write the script in sections to address each step of the workflow. You can use subroutines very nicely in doing this and it will help in debugging. Try also to keep common routines separated out and trap for errors around the smallest block of code as possible, even if it means having several try - on error clauses within a single routine. Beyond this, experience is your guide and asking questions wherever you can.


2. How does Cocoa enhance accessing the components of a program?


This is more of a comment to the developer rather than to the AppleScripter or user. One of the traditional problems with AppleScript support in applications pre-Cocoa is that it always kind of felt "bolted on" and was usually much more work than most developers liked. So while you can use AppleScript to move messages from Outlook to Filemaker today it took Microsoft and Apple developers a long time to add this capability to their apps. This was often a barrier for smaller developers to add scripting support or they would only add support in a limited way. Cocoa allows for AppleScript support to be added much more naturally and easier than ever before, so more Cocoa developers should be tempted to add AppleScript support in the future. My point about accessing the pieces is more to illustrate the advantage of what AppleScript brings to the user, and thereby the value it adds to a cocoa developer's app.


3. How to move from AppleScript to Java/ObjC Cocoa most easily?


With AppleScript Studio out now, this may not even be necessary :) If you want to pick up another language like Java or ObjC then start by thinking in terms of objects and messages while using AppleScript. "tell application 'Finder' to empty trash" has the object application "Finder" and the message "empty trash". Similarly, files, folders, windows, databases etc are objects and each has a set of messages that goes with it (set, get, move, delete, close, etc.) Once you think this way, you'll see that Java and ObjC do very similar things and it might make picking up the new language a little easier. Look at as many examples and tutorials as you can and maybe try starting a pet project to help focus your interests (graphics, games, productivity, etc.)


Hope this helps,
Brad Dominy