An Introduction to AppleScript on Mac OS X
12/11/2001Look out everyone--AppleScript is coming back and coming back big!
AppleScript has been one of the most overlooked, cool technologies lurking in the Mac OS since 7.1, but it's usually hidden in your Apple Extras folder waiting to be discovered. Now with Mac OS X, it has a new home in the Applications folder, indicating that Apple no longer considers it just an extra. AppleScript has a bright future, and there's no better time than now to take advantage of this amazing technology.
"Why," you might ask, "should we once again see what AppleScript has to offer?" I can give you three reasons: Cocoa, Unix, and AppleScript itself.
The Cocoa advantage
Creating a Scriptable Application has never been easier, and Cocoa is what brings this into reality. Cocoa is an object-oriented framework that holds information and the methods that access this information within objects. Cocoa applications are really just a collection of these objects working together to accomplish a task.
|
Related Reading
|
Each of these Cocoa objects and their methods can potentially be accessed through AppleScript, and many of the core scripting commands are gained "for free." Planning for scriptabilty with Cocoa leads naturally to good program design. Even better, if you have an existing program written using Cocoa, adding AppleScript support is probably easier than you think.
The Unix way
Unix is usually seen as an OS, but one of the strengths of Unix is the ability to combine together many small programs to build a larger program that does what you want, all from the command line.
So, you can have one program read the contents of a file, send it to a stream editor to replace one string with another, and then break it into fields and store those fields with formatting in another file. Typically, Unix does this with very small programs that have a very specific purpose (i.e., to read the contents of a file); however, most programs on Macs and Windows are more monolithic, taking care of many functions that are usually related to each other (browsing, sending email, word processing, transferring files, etc.).
Since Cocoa typically has objects as the basis of these functions, scripting will allow access to those objects and their methods and data individually. Now a user can combine them with functions from other apps, the OS, and AppleScript itself, making them work more like the Unix model and giving them great flexibility and power.
AppleScript X
AppleScript has matured along with the Mac OS, and AppleScript 1.7 found in Mac OS X 10.1 allows for new ways of doing things that are incredibly convenient.
Many applications that come with Mac OS X are already scriptable, including the Finder, iMovie, Internet Connect, iTunes, Mail, Print Center, QuickTime, Sherlock, and Terminal. Also, Mac OS X has made running scripts incredibly easy by adding Toolbar scripts and an optional Script Menu that lets you run AppleScripts, Perl scripts, and shell scripts from anywhere. With these additions, starting a work flow is as easy as navigating through your files and clicking a button or selecting a menu item.
Additionally, AppleScript can now access Web Services. These are XML-based services that use SOAP or XML-RPC to send information to your scripts over the Internet. This gives you access to updated information or live feeds of data, like stock quotes, temperatures, and currency conversions, among others.
If this isn't enough to reaffirm your belief in Apple's commitment to AppleScript, Apple has just released AppleScript Studio, which makes AppleScript a peer language with ObjC and Java for building Cocoa applications, including front ends built with Interface Builder. Clearly, AppleScript has never been better. If you'd like to see some of this for yourself, go to Apple's AppleScript Web site and take a look at the Seybold 2001 AppleScript demo. Very cool stuff.
AppleScript for everyone
|
| |
If you haven't used AppleScript before, you will be happy to hear that it compares very well with other scripting languages on other platforms. Windows uses Visual Basic (VBScript) as the basis of its scripting support, whereas Linux or other Unix OSes usually use shell scripts or Perl. While these are not the only options for these OSes, they are the most common ones. Each scripting system has its own advantages and disadvantages, but in my opinion, none are as accessible to the non-programmer as AppleScript.
AppleScript uses a nice, human, language-like syntax that is user-friendly and easy to read and understand. It even supports local dialects, so you can write scripts in English or French or German, for example, adopting that language's syntax and idioms.
An example script (from Apple) to hide all Finder windows looks like this:
tell application "Finder"
if the (count of windows) is not 0 then
set collapsed of every window to true
end if
end tell
AppleScript supports record-ability, where a user's actions can be captured as a script, automatically. AppleScript can work between Native and Classic applications on Mac OS X 10.1 and between different machines via the Internet. It has a gentle learning curve, but it can scale very well to accomplish advanced tasks. In all, this means that AppleScript has the potential to be used by not only hardcore Mac programmers, but by everyday users too. Add this ease of use to Cocoa's ability to access individual functions within programs, and you have the makings of something great.
Your first scriptable Cocoa application
Hopefully, you're now a believer in scripting and can't wait to add it to your applications. Just to show you how easy it really is, I'm going to show you how to build a scriptable application in four steps.
- Open Project Builder and create a new Cocoa application named "ScriptableApp".
- Build the project without modifying anything by clicking on the Build Active Target (Hammer) button.
- Open the Info.plist, available by opening the Products folder and then the ScriptableApp.app, and add the following to the end of current list of keys:
<key>NSAppleScriptEnabled</key> <string>YES</string>
Make sure it is formated like the other keys and comes before the closing</dict>tag.

Figure 1. Adding the NSAppleScriptEnabled key to ScriptableApp's info.plist
- Save and rebuild your application. That's it!
You have now added support for the Core Suite of AppleScript commands to this application.
You can verify this by opening up Script Editor inside your AppleScript folder in the Applications folder and selecting "Open Dictionary..." from the File menu.
Since the ScriptableApp has not been installed, it's still located inside your project's build folder. Click on the Browse button and navigate to the ScriptableApp's project folder and look for a build folder. Inside it you should find the ScriptableApp.app. Select it and you should see the ScriptableApp launch and a ScriptableApp Dictionary window come up with the Standard Suite and Text Suite on the left side of the window. Clicking on an item in the left-hand pane will bring up the syntax for that item and a brief description of how that item is used.

Figure 2. Opening ScriptableApp's Dictionary
Now, we haven't added any text objects to our application, so the Text Suite doesn't really do anything in this application. Also, some of the Standard Suite commands, like save, print, move, delete, make, duplicate, need to have more code added before they "do the right thing," but we can access many of the commands and set and get values for different elements right away.
I've written a script that shows off a few of these commands and some of the things we can do "for free." Download ScriptableApp.sit and open it in Script Editor. Run it and review some of the commands for yourself. You might also look through the dictionaries of some other applications, and review the example scripts that come with AppleScript and that are also available on Apple's AppleScript Web site.
Aim of this series
For the rest of this series, I'm going to focus on adding scripting capabilities to Cocoa applications written in ObjC first. I'll also delve into localization, creating GUI-less applications, and native scripting additions.
If you are unfamiliar with ObjC or Cocoa, please check out Mike Beam's excellent series on Cocoa programming. I won't be using advanced examples at first, but casual knowledge of both will be helpful.
Cocoa applications can also be written in Java and we will see how to add support for scripting in those applications. I'll also look at AppleScript Studio, available in the very latest version of the Mac OS X development tools, and see what it brings to the mix.
Next time
In the next article, we will talk about how Cocoa supports scripting at the object level and go into greater detail about the Core Suite and Text Suite we saw in our ScriptableApp example. We will also talk about how to best design programs that make adding scripting easy. See you then.
Brad Dominy is the head of Neoki, LLC, a small web design firm located in Chicago, IL.
Return to the Mac DevCenter.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 22 of 22.
-
Terrible
2003-12-25 20:53:02 anonymous2 [Reply | View]
I don't know what it is about tutorial writers these days, but the purpose of tutorials, especially the FIRST tutorial, is to get people up to speed so that they can do simple cheesy applications and start exploring. For goodness sakes, look at a HelloWorld Java/C/or even Flash tutorial when writing tutorials.
-
Randomize Mail app signatures with AppleScript
2003-04-08 15:58:47 anonymous2 [Reply | View]
I think an example of how to extend Mail App with AppleScript to be able randomize signatures would be great. This would be useful as a tool and as an example. It seems Mail App's plist stores signatures as RichText and this makes it hard to do simple things with your sig files:(
-
Ready for next article.
2002-02-13 05:41:04 benatong [Reply | View]
I'm right in the middle of learning scripting, by creating a trivial test application. I'm and old NeXT programmer so the ObjC stuff is old hat, but AppleScript is completely new to me.
Trying to follow the developers scripting doc's is almost impossible, when you don't have a simple example to reference for the basic's
Thanks
chuck
-
comment on the next article for SETI
2002-02-08 17:02:57 psheldon [Reply | View]
Berkeley has a bandwidth cap which my be transcended by use of a high speed cache pass of data downloads from SETI. sl-doubleclick-7-0-0-t3.sprintlink.net (pretty sure about the last "nk.net") but DNS nameservers know it better as 144.232.246.2 might take the pass. They were stuck a moment ago so I couldn't get through the links to leave this message because my netscape stalled trying to load the ad graphics.
Evidentally, the ad community needs a t3... cool.
I'm a romantic hoping for something serendipitous here because that is what SETI is about and what the world vitally needs cf Davies, but I won't be more specific here and have gone through other channels on that one.
I suppose Berkeley is having experts work on this, but they may be embroiled without informal channels, as they say in "The Psychology of Computer Programming". All I'm gonna say are the magic words for someone wise, beware the tradgedy of the commons, the classical management failure or "let's roll". Little steps Elly, little steps... Contact anyone? -
iTools might do some mediation
2002-02-09 21:49:35 psheldon [Reply | View]
Recall I suggested transfers of processed data to and raw data from Berkeley of SETI might occur at higher speed and get out of the way of the slower traffic. I have found that unix command transfer of huge files by cli with merely 56k to transmit the low low bandwidth command to transfer at high bandwidth between T1 connected computers got me way ahead on the ports ques. I don't know why the shared resource economy works, but I know how it works, fast.
The crucial thing is to send the data to and from Berkeley fast through t1 t3 whatever. I don't know about that serendipity thing when I was reminded about iTools this morning by Martha Washington in her digital hub spiel. I think what I had observed before this ACD (Apple Corps of Dallas) meeting was the graphics from advertisements coming from unix paths on machines with t3 connections, so as not to get in the way with the text that were sort of like TV programs in between the advertisements.
I don't know if Berkeley needs a t3 machine, and it had seemed to me that that compound name t3 machine made sense just from the name, to solve their bandwidth cap. Maybe I misled some folks to beat on the wrong door.
Any university already has a T1 connection, I believe, though I haven't checked my old university lately, they may have moved up towards internet 2 whatever t that movng up is.
What's more, I bet iTools with a 20 meg drive storage out there is served by os x (unix) server. That means that from there I could do high speed transfers to/from Berkeley and get out of the way fast from the shared resources. What's more, by internet application serving, I could have an applescript send that remote machine an instruction to run an application there to do the ftp, even do it at an optimal time (which I doubt is necessary, insisting on it, even for a high speed pass, might confuse this economy with the old notion of doing batch processing) because, in Oreilly's terminal column, I read that you can change the time of garbage collection task with a sudo. So, someone with a sudo access at iTools machines could, instead of garbage collection, time an ftp task.
Since Berkeley came up with BSD unix and is physically close to Cupertino, at least in my experience driving, maybe Apple could do some unix guru stuff or Bruce W. Perry who wrote the lines following :
tell application "http://..."
that let me know he knew about telling another machine what to do, a machine that could "take the pass".
Now, cli is just character strings as far as I know, so, this remote high speed ftp between unix machines doesn't have to be commanded from a unix machine or even from a mac, though it might be a nice gesture to the pride of Berkeley if Apple did it first.
Well, I'm tired. I wanted to get this out fast. I hope I have been clear. Someone knows better than me how to do this stuff, I just wanted to inspire and maybe get a little more wisdom on what multiprocessing thinking could be. Just a little. Again, I like the whole idea of project SETI, Contact, Carl Sagan and his friend, Kip Thorne. I very much liked Paul Davies "The Fifth Miracle". There, I've said it out...
-
can it do GUIs for shell apps?
2002-01-29 19:17:07 frankie1969 [Reply | View]
Something I'd really like to do is make clickable (and possibly drag-droppable) front-ends for Unix shell tools. I know about Wilfredo's DropScript, but I also want the output to appear in a standard text window. Is this (trivial|workable|painful|inconceivable)?
-
Timeline
2002-01-22 08:34:41 salamon [Reply | View]
As a new Cocoa applications developer I'm definitely looking forward to your next article. Any idea when it will be ready?
I've used AppleScript for a number of projects myself, and I consider adding full appleScrpt support (including recording!) to my applications to be a very high priority.
Thanks for doing this series!
Andrew
-
Scripter morphing Programmer
2002-01-18 09:58:50 carpenter-b [Reply | View]
I am a conventional Applescripter. I got hired on as a audio/video specialist for a distribution company, put in front of a Mac and told to learn to make it work. Learning Applescript from tutorials and books for dummies like me, I was able to get an automated system for encoding audio, video, preping images for the web and getting all this into a kiosk as well. I have been able to learn Applescript in a classroom as well. I have no training in any computer language nor in the structure of programming.
What I want to learn to do with applescript is what applescript is made to do. Getting applications to work with each other and getting then to manipulate data into something that will be a finished product.
I saw the QT video presentation of Sal, using FileMaker Pro, imaging software and Quark to create a catalog for Real Estate. Wonderful! That is what I want to do as well. And I want to make an application out of all my work. But my enviroment variables are not conventional or standard by any means.
Java, SQL, AIX, JDBC, AS/400, WinNT, MQ series and IBM's DB2 have been brought to the table. Not to mention, Web servers, FTP, and all kinds of other servers. I need to find a way to get my enviroment involved. In other words, real programming. All my work is devalued because it is scripting.
OS X and Applescript Studio have to be my hero.
-
Wanted: AppleScript sans ObjC info
2001-12-21 10:47:09 reggoboy [Reply | View]
I'm a Mac owner since 1984. But I'm a professional programmer. However, though I've done lots of Windows and Unix programming, I've never done any on the Mac. I've always found it rather inaccessible, with strange development environments and the need to but a bookshelf of Inside Mac books even to write a Hello World program...
My hope with AppleScript and the new Studio is that it will allow me to make full apps without needing to know ObjC, especially since it has full access to Cocoa. I don't want to touch ObjC or Java. On Windows, VB is basically an environment with a bunch of widgets that you can script with a simple scripting language. That's what I want your article series to tell me how to do, presuming AS is capable of that. I want to know how to make apps from the ground up with AS, and that's it. Hello, World would be a nice place to start.
Thanks!
Dave -
Wanted: AppleScript sans ObjC info
2002-01-04 20:45:52 benjk [Reply | View]
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.
hth
benjk -
Wanted: AppleScript sans ObjC info
2001-12-22 18:10:26 bdominy [Reply | View]
Hello Dave,
With the release of AppleScript Studio, it certainly seems like you will be able to do just this; however, we probably won't touch on studio for a little while for two reasons. First, it is a 1.0 release and there may be revisions in the near future. Second, I've just started playing with it myself, so I cannot offer much more in these articles than what comes with the documentation right away. But I do consider Studio to be about the coolest developer tool addition Apple has released since Project Builder, so we will touch on it for sure.
The goal of the beginning of this series is to get developers who want to use Cocoa excited about adding AppleScript support so that more applications can be used in scripting. I've been very excited about AppleScript for years, ever since it helped me process hundreds of molecular images into a website on a Quadra when I was in college, but many apps did not support scripting at all or very well. The reason for this was not developer apathy, but rather that adding scripting support to pre-cocoa apps was very difficult. It represented a major investment for the developer and had little perceived value for the user. Kind of a chicken and the egg proposition. Cocoa changes this situation for the developer and lowers the barrier for them. I'm hoping developers who read these articles will once again consider adding scripting support to their new apps written using Cocoa, once they see how mush easier it is. So, we will spend some time seeing how to do this using ObjC and then Java, then move on to see how Studio does it.
Thanks for reading,
Brad -
real basic claims counterpart to visual basic
2001-12-22 10:21:35 psheldon [Reply | View]
Salesman claims you don't have to learn frameworks to start making stuff. And it is object oriented, so you can get the new wisdom there, if that is what you want. I think that they might even give some free advice, but I don't know how much. I started reading Joy manuals and found the tutorials soon petered out. The first few chapters gave you the urge to buy and then, soon, I hit the brick wall of unpolished writing. It's always there at the beginnings of things.
Now I give some rambling thoughts. Hey I don't write as good as the guys who write these columns. I try to understand you and I try to understand them, that also makes for rambling. Rambling is risky at Christmas when people might tend to be grouchy.
Agreed, we have a potential polemic here. What the heck is a "potential polemic"?
I know Apple spent big bucks buying Next Step code as part of the deal of getting Steve Jobs to bail out the company. Now they want a return on their investment and that is "us" although I don't think we quite rank with Adobe, etc. However, remember those guys are way cross platform. Already you want to be. Are we that sort of heavyweight? Maybe. Will heavyweights have time to give us wisdom? Lonely out there in the crowd where you and companies are easily replaceable.
One might imagine that were Apple stock to go down then some other language would be the climax plant and cocoa would not get any sunlight. How does a programmer hedge his bets when daytraders get most of the dates? Well programmers pay attention to the quality dates they get and their quality data screens and don't just dose out with 5 second sound bytes, for one thing.
;-)
I learned newtonscript and got a long time friend who gave me some wisdom, who had time to give me wisdom in a small market nitch. That was my bet. Newton is no longer sold, but my friend is still thriving and sending his children to school (a bit less time). I don't think the $1000's I spent on newtons or the time I spent on newtons a waste. I got a lot of confidence and a feel for the magic of guys who make systems or know them so well that they can make compilers. I got a sense of mystery. If you think the guys who make real basic don't know cocoa frameworks themselves, I've heard they are definitely sourced with so called "next step geeks".
I've myself subscribed for maybe five years to ADC CD's and have hardly looked at them because I wanted to get an itch to become an inside mac geek. In fact, I bought inside mac in 1985 before I bought my mac plus or was it even plus computer.
What's an itch?
I wanted to learn to knowledge navigate all the managers of Inside Macintosh (managers now almost defunct). My fantasy was to distribute my own wierd code as a signature of my knowledge in obscure Physics and be found by someone who would give me a suitably wierd life. I did distribute alternate universe navigator and it gave me confidence I could eventually publish something wierd to the more sought after publishers. It also gave my professor confidence. It is hard to keep confidence when you are working on a Ph.D. that takes 17 years.
So that's an itch.
Now they have frameworks, next step frameworks, that Apple might be "desparate" to recoup their investment in. Many think that even hinting desperation means to lose status; with me it means folks with time who aren't beseiged by mobs and charging 90 cents a minute at least at Oreilly. Cocoa isn't quite the nitch market newtonscript was, but there seem to be guys out here who have time to give you the time of day.
I had my fill of huge corporations that translate programs into older languages to make them compatible with the old men who invested themselves in the power structure and want to enforce their legacy honor. Languages develope and leave room for the next generation (even though I'm pretty old myself, I haven't invested in a legacy)! I'm really excited about language developement. You may not be. But languages let you develope science fast and that means less sitdown time economy.
What's sitdown time economy?
That's a guy in charge, drumming his fingers, employed to wait for something to get done with an archaic langauge that he could get cheap, while you get beaten up at a lower salary, tempted to become him, debugging a program and not doing what you should be paid for, doing science or more generally wierd stuff.
For example, I knew a lead software engineer who only got to work on other people's bugs, but was glad when she got something more secret on a grant for herself so she could use a friend incompatible pascal compiler. Other times she was translating Fortran V into Fortran IV and disgusted.
Compatibility to me means that when you get good you are tasked to debugging other people's programs all the time, maybe not so good a deal. Who do you blame when things continue to go wrong? Do you really have friends? Oh, she wept when I left Rockwell. I was the only one who dared to argue with her and then say I admired her moxy, very long ago.
Where does the individual programmer who has taken courses in pseudocode to avoid the religious fanaticism for a language and knows the art and not the hype go? When I took my CS classes about 13 years ago, object oriented programming was not in the coursework. Now, a kid I tutor claims he is learning C++, but his older brother admits to only taking a test in C. What do they study nowadays? I suspect something to bring in large numbers of the uneducated to value their language, not guys with legacies dragging behind them. But, I have my legacy dragging behind, my ability to learn science and structured things, to compose. Is that your normal legacy dragging sort of thing. Is that your legacy dragging sort of thing? You know a lot of programming, have that experience. Is your old code your experience? Or is it rather your capacity, that you've learned through experience, to experience.
I consider myself a student. I've learned that I can learn. I haven't learned that I can contribute, yet.
Times are changing from the old pseudocode. Perhaps the textbooks are dealing with object oriented pseudocode. I imagine that the guys who made the os x system studied and maybe even wrote those text books. You can't get the textbooks they wrote to Apple's managers. There's mishy moshy stuff in the threads with guys asking what to do about one or another speicalized thing and other guys answering. I could go there and cry out I didn't get my colored pen to work and hope some kind soul would debug my code or I could see if I have learned anything from all the columns I read and pound my answer into a subject line to hit everyone's interest as a genuine contribution. Could I do that? I don't know, but I know how to go there. Maybe my complaining about the threads is because I am chicken about writing too much or too little to them.
I enjoyed data structures course. That was in pseudocode. I'd like to merge the idea of doing data structures and doing objects not have somebody debate with me the virtue of objects over data structures, someone who hasn't taken the course.
There is also something I am finding following columns on cocoa or obj-c. As a guy writes a column longer and longer, he sort of developes skill in his rendering language. Maybe it is the use of some other guy's language and maybe it is his own.
It is reminiscent of my friend in newtonscript, a friend who wrote a compiler with apple's compiler to build with. Terse language using object oriented terms. My newtonscript friend could give me a hint on how to program using very few words He made hypertext documents for newtonscript and with just those keywords pointed me in the hyperscript. I learned he had wisdom, I learned I wanted to be like him.
Yeah I have misgivings that perhaps these columns aren't going to teach me to do my science but rather have me join a pyramid scheme of cocoa salesmen, but I am not too afraid of this, perhaps because I find I can read the columns real fast now and it isn't all that much of an investment. I am also seeing how these guys make a story out of something that I couldn't as yet and that is a very general talent, nonlanguage specific.
Well, I hope that you got some ideas to inspire. This wasn't all that heavy technical reading so it should have been a quick read. It wasn't a quick write. Having choices (do I do real basic, do I learn a difficult new language to be in a small intimate group for awhile until the world changes, do I become a daytrader with a four hour attention span of money) isn't necessarily a curse. I'm slogging along and finding out how.
I knew a guy who joined many many clubs in high school but was not a member of one of them. He would duck his head in the door and merely ask, "is everything in order". He got into Harvard for his leadership abilities. I don't want to be like him.
Join a club you like. See where you go. It's an adventure just being yourself, sometimes I find it scary, and Merry Christmas.
-
Beam
2001-12-17 17:25:38 suthercd [Reply | View]
Not usually this verbose, but followed the link to the Cocoa introduction by Mike Beam.. looks like what I was looking for.
C
-
First article
2001-12-17 17:02:22 suthercd [Reply | View]
Applescript is very familiar- Cocoa and C++ Object programming much less so. The initial book from O'Reilly on Cocoa was more of an overview and did not begin to describe the underpinnings.
The Studio mailing list that has been set up on the Apple boards shows by the messages sent that the people who are able to quickly use Studio have considerable experience outside of Applescript.
The exercise in the article was very helpful as well as the script to download. Looks like the learning curve is initially steep- hope you can provide a guide to learn to use Studio as quickly as practical
Craig Sutherland -
studio mailing list?
2001-12-18 22:56:47 psheldon [Reply | View]
One page says 12 Dec 2001 Applescript Studio available :
http://developer.apple.com/macosx/
Linked to page says available later this year :
http://www.apple.com/applescript/macosx/ascript_studio/
I think there are guys who buy in at higher prices and get betas sooner and these guys are on that list? -
studio mailing list?
2001-12-19 06:13:47 suthercd [Reply | View]
As a paid up Developer, I did get access to Studio 4 days before the general release. Not a huge diff.
How is your experieicen so far in learning Studio?
Craig -
no experience studio
2001-12-19 12:25:54 psheldon [Reply | View]
Got the cheapest cd distribution and didn't see it on December issue. Suspect that the 12th Dec brackets mean they couldn't publish it on my cd delivered month first and it will be on next months. What I suspect that I must do, if I wanted it now, is download the entire disk image of all developer tools. I think I recall now reading that you couldn't separately download it. That might mean a trip to the apple store where I can access by high speed Airport.
-
Dear Santa,
2001-12-17 09:34:59 o1eal [Reply | View]
Looks like a great series you've got underway. Though I'm not sure it fits into the aim of the series as you've defined it, here's what I'd like to see:
1. As a self-taught AppleScript programmer, I hunger for insight on the most intelligent way to accomplish a given task. Too often in the world of AS, we're told we can do things "any way we want." This flexibility is great, but it's also great to hear the perspective of those who understand programming in a broader sense. i.e., what factors should I consider in *choosing* among the many options?
2. I'd like some clarification on your comment that Cocoa allows you to use only a small part of an application in a script. I thought that was what I'd been doing for a while...loading Outlook Express, getting a message from it, copying that message to a Filemaker database etc. How does Cocoa enhance this?
3. What can I do to move into Java or Cocoa programming most easily? What's the best approach for someone with a fair amount of AS experience, but no formal training in programming?
Thanks for what you're doing. Judging from the first article, this promises to be a most enlightening series...
-Pete -
Dear Santa,
2001-12-20 01:38:56 bdominy [Reply | View]
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 -
how I sort of learned to program but still feel ignorant
2001-12-18 21:55:13 psheldon [Reply | View]
I think the biggest step for me programming was to learn to break things down into small chunks. Programming suddenly, in one week, became fun while the senior programming engineer went on vacation. She expressed mock or actual real jealousy when I came back. I've studied a 800 page book from code warrior on making a puzzle. I really had it illustrated how code can be distributed in a template. All of a sudden, when I was about to finish this monster of a pdf file, the author said, OK you had the example, now go fill in the code to make it not only be a puzzle maker but also a text editor. In other words, the author said you haven't really finished this book until you've written one of your own. That scared me and I didn't make a text editor. On the last pages after that brick wall or stumbling block the author anticipated how much easier would have been that brick wall when the world developes object oriented programming. Then I didn't feel so guilty just finishing that ancient monstor tome and laying it down and getting down to wondering how to approach (again) learning object oriented programming.
I had already taken Apple's object oriented pascal programming $300 kit. The woman narrating sounded too businesslike, but I forced myself to listen to it, longing for her to allow me to watch the video "How to creat a monstor". The professor who was supposed to be interested in object oriented programming went to sleep and, after I got past the video, I could excite my actual thesis advisor in a mere single hour session. Boring women and monstor movies didn't work for me. I immediately learned that Maple and Mathematica had a one liner called dsolve or desolve that would allow me to do wierd math with one line rather than a class library. For a few years, I "fled to parts unknown", but continued to wonder how object oriented programming might affect my studies in physics.
From Mike Beam, I learned that Apple presents you with commented method stubs of distributed code for you to fill in or perhaps make overrides for. Those comments seem reassuring. The notion of putting in overrides or downright additions to your own classes that inherit from fundamental or "Apple supplied" classes intrigued me as a way to modularize and make that programming fun. I got lost out on my own, but that's alright. It will mean that I will respect and remember the tricks taught me pedantically so I won't get lost again. I don't know whether someone else debugging my code teaches me all that much compared to the pain of the bug hanging around bothering me awhile. It's Christmas and finals time and Mike hasn't had time to find where I goofed, so I let it go and do some other reading.
I tried to make things I might enjoy to sort of reinforce what I learned making them and found I could intensely enjoy getting into solving something or other, sort of a soaring free feeling or maybe a feeling of stamina that I'll keep at it until it makes sense.







I run: OSX10.4.5 on a powerbook G4 - 1.5GHZ. What am I doing wrong? I can`t get anywhere... I have installed X-Code and really want to learn!
Please do advice me how to get by this problem!
Thank You!