Configure player

Close

WWDC Index does not host video files

If you have access to video files, you can configure a URL pattern to be used in a video player.

URL pattern

preview

Use any of these variables in your URL pattern, the pattern is stored in your browsers' local storage.

$id
ID of session: wwdc2002-902
$eventId
ID of event: wwdc2002
$eventContentId
ID of session without event part: 902
$eventShortId
Shortened ID of event: wwdc02
$year
Year of session: 2002
$extension
Extension of original filename: mov
$filenameAlmostEvery
Filename from "(Almost) Every..." gist: ...

WWDC02 • Session 902

AppleScript Studio Introduction

Tools • 50:39

AppleScript makes it incredibly easy to integrate graphical applications, web services, and even UNIX scripts into a coherent workflow. Now with AppleScript Studio, you can build full-bore, rich Aqua applications entirely in AppleScript, leveraging the power of Interface Builder, Project Builder, and Cocoa. Come find out how easy it is to create graphical front-ends for script-based applications.

Speakers: Tim Bumgarner, John Coelho

Unlisted on Apple Developer site

Transcript

This transcript was generated using Whisper, it has known transcription errors. We are working on an improved version.

Good afternoon. Welcome to session 902, AppleScript Introduction. AppleScript Studio has been a big hit since its inception. It allows you to create full-bore application with gorgeous Aqua interfaces. And to tell you all about it and show you some examples, I'd like to introduce the AppleScript Studio engineer, Tim Bumgarner.

Thank you, Jason. I have a good friend of mine that suggested that maybe I should change my title to Mr. AppleScript Studio. Besides being a little bit presumptuous, it actually appealed to me. So I thought about it for a minute, and then I remembered what the acronym for AppleScript Studio is.

So who wants to go through life being Mr. Ass, right? All right. Seriously, it's actually, AppleScript Studio is a real team effort. It took a lot of people and a lot of hard work that we were able to build on top of to bring this great product to you.

And this is a bit of our agenda today. I would like to do a quick introduction, talk a bit about the process of building a studio application, and then we're going to start on the other end of the spectrum, and we're going to take an already existing Cocoa application and add studio functionality to it.

And then we're going to talk about using other languages. And when I mean other languages, I don't mean using other AppleScript dialects. I mean other programming languages. And then we're going to talk a bit about what's in store for AppleScript Studio looking forward. And if I... Don't talk so fast, or talk a little faster, which is not a problem for me. We'll actually have a little time for Q&A at the end.

So what is AppleScript Studio and what can you do with it? What it is, it's that we've taken these great technologies at Apple. We had Cocoa, what everything is built on top of it. We've taken these developer tools, Project Builder and Interface Builder, and we integrated it all together with AppleScript.

We integrated into each of the tools. We developed a runtime framework such that we could build and run native Macintosh 10 applications. And so it's really two things. It's a development tool or a development system, and it's also a runtime. That's sort of where the studio name came in.

So let's talk a little bit about each of these components. The AppleScript kit is a system library framework, and this is sort of the foundation for AppleScript Studio. We need this for both the development tools and for studio applications to run. It contains the script suites that make a studio application scriptable, and most importantly, it provides the link between Cocoa and AppleScript, so that when you click on a button, AppleScript kit waits for that, grabs that, and then executes the script you've attached to that button.

And then on the development side, we've got three plug-ins into Project Builder, and then we've also got an additional plug-in into Interface Builder. And we'll take a look at each of these. The ASK plug-in is our editor, so we can actually edit AppleScript files right in Project Builder, taking full advantage of the check syntax and the things that we're used to in Script Editor.

The dictionary plug-in provides us with a built-in dictionary viewer inside of Project Builder, so we don't have to go into Script Editor and to... to look at our scripts, or the various dictionaries of a scriptable application. So then we've also fully integrated into the debugger plug-in UI, so we can debug right inside of Project Builder.

On the palette, what we have is we've plugged in a palette so that it provides the AppleScript functionality we need inside of Interface Builder. It provides an inspector so that any time you want to add AppleScript functionality to your nib file, you just simply go to that palette. So what can you do with AppleScript Studio? Well, we can create native Macintosh OS X applications. Fundamentally, what we're creating are Cocoa apps. And so once you've built it and delivered it out, people can just double-click and run with it. It really is a Cocoa application.

And of course, since it is a Cocoa application, we can take advantage of everything that Cocoa provides. It provides some amazing, great services, has a great, rich user interface, and we get to take advantage of all those things. We can take advantage of drawers, sheets, sliders, all those wonderful things.

But really, the real power that we get to is we get to leverage off of AppleScript. Because not only can we talk to local applications, we can talk to applications on other computers. We can actually then also talk to web services. And that's a great direction that we're moving in.

And some of the other things is that not only can we talk to other applications, we can actually talk to the UNIX foundation that's underneath Mac OS X using the do shell script command. That really opens up the possibilities. And then also, then we can leverage project builders' ability to include other programming languages. So we can use C, C++.

We can do Objective C, Objective C++. We can do Java, either through the bridge or directly. And so we're going to give you some demonstrations of that today. So what we'd like to do is actually go through the process of building an AppleScript Studio application from scratch. And to do that, I would like to bring out John Coelho, who's our Q&A manager, to help me with the demo today. John? Thank you.

All right, so what we're going to do-- and I apologize to those that came to the kitchen on Sunday. We're going to see a little bit of the same thing. But we're going to build a currency converter application. And this application is going to let us enter an exchange rate, some dollars to convert, and give us a simple calculation. And we'll show you how easy that is to do. So John has chosen the new project.

[Transcript missing]

Okay, and you can see that Project Builder has opened a project for me. It's already been set up so it'll build a Studio application. It has already added a default empty AppleScript for us. It has our main menu nib, which contains our user interface. And then it has this file that John has selected called AppleScriptKit.asDictionary.

What this is is sort of a freeze-dried terminology, because we haven't built a Studio app, and since Cocoa apps are dynamic terminology, we needed a way to be able to look at the terminology before you've built an app. And so this is what we've come up with. And so he's simply selected the application object in the class, and we can see all the various elements and the properties, and we can browse through that. And there's also, under the file menu, we can choose Open Dictionary. So we don't have to go to Script Editor, we can do it right here.

And this will show us all of the scriptable applications that are on our system, and we'll choose the finder. And you can see, again, all the various classes and events that are available. All right, let's go ahead and close those, John. So let's go ahead and get started with building our application. And we always do that by going into our user interface. Let's double-click on mainmenu.num.

And it opens up our project into Interface Builder. And it just starts out by default with an empty window. First thing I'd like to do is go ahead and change the title of the window. Call that Currency Converter. And we're going to go ahead and start adding some text fields, because what we want to do is enter a few different values and do a calculation. So go ahead and drag out a text field.

And you'll notice as he drags around Interface Builder, you get all the nice guidelines that show us where the Aqua thinks that it should be placed. Make it a little bit wider. And then I know that it's going to contain numbers. So there's also another object in Cocoa that's called a formatter, a number formatter in this case. And you just drag it right on top of that. The other thing is that since it's a number, we want to right-align it. So we go to the Attributes panel.

And we right-align that object. Now I think we're ready. We can go ahead and duplicate that a few times. A couple times there. There's one and another one. All right, great. Now I know that the third one is going to be a calculated field. And I don't want to be able to edit. So we're going to disable that by checking off the editable. But we do want it selectable so they can copy the value. Now we need some text labels.

And we're going to put some values in here.

[Transcript missing]

And then another way of duplicating objects in Interface Builder is you can just hold down the Option key and drag it up. And again, Aqua guidelines show you exactly where the text baseline is. And then we'll edit those values.

Great. So now we've got our text field. Everything's laid out pretty well. Let's go ahead and drag it up to the left and sort of center it where it should be. Resize our window. Oh, the other thing we need is we need a button. And we're going to click on that to actually do our calculation. Rename it to Convert.

Another thing we like to do is make it the default button. We do that by going to the key equivalent pop-up and choosing return. Not entirely obvious that that's how you do it, but that's where you do it. All right, let's shrink that window up a bit. And let's test it. We can actually test the interface right here in Interface Builder. So we go to the File menu and choose Test Interface. We can enter a couple values.

See the formatter in operation. It automatically inserts the proper number of decimal places, commas. We can just tab between the two fields. But it looks like we can resize the window. Let's try that. Well, oof, not at all what we want. So we better go back and turn that off.

So we can just quit testing, and we'll go to the window menu, palette, and turn that off. Okay, great. I think everything looks great. So now we've got our user interface in place, and we still haven't done any AppleScript work. Well, now we're going to go ahead and start doing that. And we do that by going to the info window and choosing the AppleScript pop-up.

Or the AppleScript panel from the pop-up. And I want to just talk for just a minute about that. So what it provides is the ability to name objects. And I don't mean name as in the title. They're named as in from AppleScript, so that you can talk to those objects by their name, not by index.

And also, it shows you the index. So as he clicks around on different objects, you'll see that the index changes to show you what those indexes are. Now, the next section is the event handlers. And every object has a certain set of event handlers that it can actually employ or produce or generate. And so as he clicks on different ones, you'll see that there's a different set of event handlers that are available. So let's go ahead and start naming, John. Let's start with the window.

Go ahead and click on the window. We can click on the back. And we'll call that main. And then we'll name each of these text fields. And so the first one we'll call rate. The second one we'll call dollars. And the last one we'll just go ahead and label that amounts.

And then we need to name our convert button. Convert. And now this is the point where we're actually going to attach a script. So when you click that button, we want some AppleScript executed. And you do that by simply clicking on the click check box. And then we're going to attach it in-- or put it into the Currency Converter AppleScript.

The one thing I didn't talk about is the script section at the bottom. What it does is it lists all of the scripts that are in your current project, and it also lets you create new scripts right from here. We're going to go ahead and click Edit Script.

And we've already got it up. Notice that in the script, there weren't any handlers called clicks. It automatically generated it for us. And we're going to go ahead and insert our script. Tell window of the object. Okay, the very first line. Basically, the object is the thing that was clicked, so that's going to be the button.

And a button, through its inheritance, has a property called window. And so to simplify things, we know that we're going to be asking several UI objects in the window, and so the simplest thing to do is just say tell window of the object. Otherwise, we'd have to do it on every line.

And so what we want to do is get the contents of text field rate and convert it to a number. We need it as a real. So let's go ahead and add the next line. We do the same thing for the dollars. And then very simply, at the end, we take that calculation, the rate times the dollars, and we put it back into the contents of text field amount. Let's go ahead and finish that up. And that's it. So if anybody's actually worked with a currency converter application in the OpenStep days, this is just a little bit simpler. So let's go ahead and build and run. Okay.

And again, it's going through the whole build process, build and link the application. Go ahead and type in a value, 1.5. Let's try 2,000. And he clicks on the, go ahead and click on the convert button. And nothing happened. Alright, debugging 101. Alright, let's go to quit. Now let's see what we do wrong.

Let's go into, it's not going to be the problem in here, it'll be back in Interface Builder. You typed in amounts. Okay, go ahead and put it here. It was supposed to be about... Okay. And run. Good catch. What I need, QA team right out there. Way to go, guys. All right. There we go. 3,000.

All right. Now, I guess we could have taken that time to check the debugging. We're going to do it again anyway. So we're going to actually show you how well the debugger is integrated. So let's go ahead and quit the application, John. Let's go back to the script. And let's put a breakpoint just about where the rate's going to be set. This time we're going to choose Build and Debug.

And our window comes up, and go ahead and enter your values. And click on the Convert button. And this time, it'll break and stop on our breakpoint, just like it would if it were in Objective-C or any other language. And we can actually see we've got our frames in the one section, we've got our variables in the other part. And then, of course, we can see what current line we're executing. It shows us the globals for AppleScript. Yes, you actually could change the value of pi right here.

It shows us the properties of this file. And then, of course, the thing that we're most interested in this particular case is the locals. Now, right now, it says-- it's hard to see. It's not quite that large. But it says, view ID of window two-- window ID one, I'm sorry-- in Jaguar. That's for you.

I actually remembered. It's actually going to say button ID too, so it'll actually show you what the type of thing is. But let's go ahead and step across that. And now it actually, the rate has been defined, so it shows up in the debugger. Let's step one more time, the dollars. So we can go right into the rates, double-click on that value, and we can change that. Let's make it a three. Makes it easy to remember the calculation. Okay. And we'll hit continue, and let's go back to the application.

And you'll see that instead of 3,000, we got 6,000, so I can actually change the variables as we go. All right, thank you. All right, so that's debugging. So it is built right in and works just like everything else. Now, wouldn't it be great instead of having to kind of think of some number as an exchange rate to actually go out and find the current exchange rate for any given country? So we're going to actually take advantage of AppleScript's built-in support for XML, RPC, and SOAP and to employ a web service. And so let's go back into Interface Builder.

Actually, yeah, let's go find the service, and then we'll worry about that. XMethods is a great place to go find some web services that are out there. And as John scrolls down, you can see that there's all kinds of different services available. You can find out what the weather in Chicago is. There's a Google search API. But I do know that at the very end of this long list is a service called Currency Exchange Rate.

And given two countries, it will give me the exchange rate between that as a live value. And if we look at the RPC profile, it actually shows us all the parameters that we're going to need to take advantage of this web service. So we'll shrink that down so we can reference it.

And let's go back into the Interface Builder. Go ahead and minimize that window, John, the other one. There you go. And let's go into Interface Builder. And we need to make our window a little bigger. What we're going to do is we're going to put a pop-up above there and put a few countries in so that we can choose a country.

And then we're going to do our web service, and then it'll put the value back in the exchange rate for us. So it drags it up. Oh, you hit that right. Perfect. Didn't even have to change the size. Okay, good. And let's go ahead and change the value. Or you can drag off the field. We'll call that country. Right-align it.

[Transcript missing]

Let's see, another Japan, that would be fine. And just for sanity's sake, we'll put in USA just to test our service to make sure, because it should be, what, one, right? So let's put USA. Now, it would be nice if the service actually provided you the ability to go find out what countries they supported. Unfortunately, this particular service doesn't do that, so we'll just pick these. So let's sort of resize everything, make sure everything's where it belongs. Actually, it looks pretty good. Okay, good.

Now, the next thing we need to do is when somebody chooses that pop-up menu, we want to have some script execute, just like we did before. So we're going to select that. We're going to go ahead and click on the action handler. That's the one that will be called when we choose something from here. And let's go to edit script.

And then what we're going to do is go ahead and put in our script for using the web service. Now the very first thing it does, go ahead and select the title of the object as string. And the object, of course, is the pop-up menu. And the title is the currently chosen item, or the text of it. So that's what we want. We're going to pass it to a handler called getRate.

And then once we get that value, we put it back into the text field called rate. So let's go down, and we're going to have to add our getRate. And we pass it the country. We set up an initial value to return so it has some known state.

This is an interesting one. Set to country to get plain text. I'll explain that in a minute. All right, go ahead. From country to USA, because we're always going to be converting from USA. And now this is where it gets interesting. So just like you talk to an application, like Tel Application Finder, it's just as simple to employ a web service by Tel Application, the endpoint URL is what it wants, or a URL. And if we look in our window down there in the WSDL, we can actually see that it shows us what the name of that is, and that's the value that we have. So let's add the next line.

All right, and this is where the magic basically happens, the call soap. This command, given all the parameters that you see, and we'll talk about them in a second, wraps up all these. It's basically an AppleScript record. It sends it off to the Apple Event Manager. The command tears it apart into XML, properly formatted, sends it across the wire, waits for the response, it comes back as XML, and then reconstitutes it back into an AppleScript object that we can understand.

In this case, let's look at the output parameter in the WSDL. What is that? I'm going to lift it up a bit. The output parameter in this case is just a float, so what we're going to get back is a simple number. And there's the various parameters in there, but let's go ahead and continue on with the rest of the line.

Go ahead and get right. Now, I said that there's something about that get plain text. There's a known bug in the call soap that it actually has to have... It has to have the actual text, so it's just a workaround that we have for the moment so you can get from Unicode text, because everything in Studio, because it uses Cocoa scripting, is Unicode text, which is great. But unfortunately, it's just a known workaround. We'll have this fixed. Go ahead and just go through it, John. All right, great. Let's build and run this. See if it works.

All right, so there's our-- we'll go ahead and choose one. And there's our value. So it went across the wire, got the value, and plugged it in. And we can choose England. Let's see what the yen is trading at. 128. It's been about the same for the last few days. And then he can enter his values and do the calculations and do a conversion. All right, great. Thank you, John.

Slides? Okay, so that's how you start from scratch and build a Studio application. And it really is nothing more than that. You just kind of keep iteratively building your application, just keep adding a little bit of user interface, attaching some scripts. So what I'd like to do is start at the other end of the spectrum, because when we thought about this project, we actually saw a wide spectrum of different users, people that could use Studio. And one of those that we wanted to actually work with are Cocoa applications, and being able to actually add some Studio functionality to that.

And so there's a great scriptable application called Sketch, and it's fully scriptable, which makes it even better. And these are the things that you need to do to make it a Studio application or Studio-enabled. And the first is you have to add the AppleScript Kit framework. You need to link against that.

That's what provides all the functionality. And then you need to add a build phase, or an AppleScript build phase, so that Project Builder knows how to compile that AppleScript. And then what we're going to do is, once we've done that, is we're going to add a change color panel, so that we'll add a menu item, be able to choose that item.

And it'll bring a sheet, and put it right in our document window, and we'll be able to do something with that. So let's go back to the demo, or to the demo one, please. Alright, so let's open up Sketch. This is the project you all know and love. And what we're going to do is go ahead and select our external frameworks and add our AppleScript kit framework. And that's right there in System Library, Frameworks.

All right, great. The other thing we need to do is add an AppleScript build phase. And we do that by going to the target window. So these are the things that we do for you when you choose a studio template. They're all set up this way, but we need to add it here in this case.

And he just simply goes and adds that build phase. So now that whenever we add an AppleScript, it'll end up in this build phase and build appropriately. All right, so I guess the other thing we need to do now, let's go ahead and start editing, and we'll add our menu item. So our main menu is really draw2.nib. We're going to add a menu item somewhere here. And you can just simply drag it out. And let's go ahead and add a little spacer there. Change that to change color.

Now, so we've got our menu item there. Now what we need to do is actually attach a script to that. And there's a menu category of event handlers. We're going to choose the Choose Menu item. And now you can see that there aren't any scripts in the project yet. So we can go ahead and click on New Script right here. And we're going to call it Change Color.

Notice no extensions, or at least there anyway. Okay. And now the next thing we need to do, that's our menu item. We've got something wired to it. The other thing we want to do is actually add our panel. And for the sake of time, we've got one that's pretty much built. We'll just add it to our project.

[Transcript missing]

So I checked to see if that flag is true. And if it's not loaded yet, we're going to go ahead and load it. And then we just set the flag so this only happens once. And now we want to get the window that we created. And we gave it a name called Change Color. And then we're going to get the front document window.

Keep going. And then we're going to display the panel attached to the document window. Now it's the attached to portion that actually is going to present it as a sheet. If I said display the panel, it would just put it up as a panel or as a dialog. And this way it's going to come out as a sheet. So let's go down and fill out the click handler.

Now what this one is, is this hand gets called if you click the Change Color or the Cancel button in the sheet. In this case, we want to see which one was clicked. We want to know if the object was changed color. And then again, we do our Tell Window as a shortcut. And we look at the current color of the color well. We see if the checkbox is on for fill ovals. Continue. Fill rectangles, and then fill text.

So we get our various states, so we know what we have. And now since we're talking to Sketch as an application, we couldn't pull its terminology in because it's not built yet. We actually have to use using terms from. And this is something we're looking at how to work with.

And go ahead and do the using terms. And we're going to tell the document of the document window. If the fill ovals is on, we're going to take advantage of AppleScript's really powerful utility, or feature that you can say every color or every of something. So in this case, we're going to set the fill color of every circle.

And that's a class. It's not the selected items. It's just going to go find every circle in my document and change it to this color. And then we do the same thing for all of these others, the rectangles, the text areas. And we just finish up the rest of the script.

And then at the very end, we want to close our panel. We've finished with it, and we want to make sure it's closed. Now the last thing we need to add is our other handler for Get Front Document Window. And then simply given the front document window gets the title and finds that we're going to have better support for documents, and we'll talk about that later.

So let's do--the one thing we forgot to do is that he'll notice he's clicking on the Check Syntax. And when he does that, it's just like it is in Script Editor. It does a compile and then gives us-- makes sure everything's correct. So let's go ahead and build and run that.

Now you might ask, why would I want to do this? Why would I, you know, I've already got this Cocoa app, why would I want to do it? Well, there's a lot of different reasons. One of them I can think of is maybe for prototyping. You've got some new feature that you want to build, and you're not sure you want to invest a whole lot of time in order to add this feature just to see if it's going to work out well. Well, it's a great way to prototype it. You can put it together very easily, just a little bit of script.

But I think that actually you'll find that once you start this process, you might find that it's just as good, there's no reason to actually switch it over to Objective-C or whatever your native language is. But the application is up because it's a much faster machine than what we tested on. And you can see that we are going to add some various graphic objects here. And he's going to type in some text. And if this demo works correctly, he'll choose a change color.

Two for two. All right, let's quit. Go ahead and quit the application. I know I was tempting, Faye. All my rest of my demos worked fine all week, so. No, no, not here, the menu item. Oh.

[Transcript missing]

I was too busy blathering to notice, so... All right, there we go.

So we got our sheet just dropped right down, and we're going to choose, let's just change rectangles, and it applies that color. Let's choose it again, and this time, let's click on the color well, and we'll change it to some other color. And go ahead and click on the change color. So you can see it's just applying it just to those classes. Thank you, John.

All right, slides please. Okay, so we talked about how you actually start with a Cocoa application and add some Studio functionality to it. Nope, turn this the right direction. There we go. Now the next thing I'd like to talk about is how you can actually take advantage of all the other programming languages that are available.

And you can, from your AppleScript in Studio, I need to qualify this because it doesn't work from scripts outside of Studio, you can actually call any of these languages that you see listed here. And the key to it is the call method command. This call method, you can jump into Objective-C code, and then the Objective-C code can let you get to these other ones.

And then it also will let you call into not only code that you add, but it can also call code that you have, that Foundation has already provided for you. And we're going to give you some examples of those. And so I just want to talk for just a moment about the various, the call method itself.

And you'll see that the first, there's really two variants of it. There's really one command, but it has a couple different optional parameters. And the first one is of object. So you say call method, method name. Method name is the Objective-C method that you want to call. And if you pass it an object, it will actually call.

And you call the method of that object. Now if the method happens to take some parameters, there's an additional parameter here. And there's two choices. You're going to have with parameter. So if you're passing one parameter, you would choose with parameter. If you're passing two or more, you would pass with parameters. And you would pass it an AppleScript list of those parameters. The second one is for classes.

So we can also call class methods by, say, simply passing the class method name. And then you pass of class. And you pass it the string name of the class that you want to call. And this is really cool. And this is really great because you can easily call Java code doing this, calling into static objects and things of that nature.

So here's a few examples of what that might look like. So for instance, if I want to get the title of a button, well, the AppleScript way, of course, would be just title of button. But so for this example, I can call title, the method called title, because that's actually the Objective-C method on NS control, I believe, of object button one. The second one then, of course, is a little more complicated. It actually takes one parameter. So this is going to be seven. So I'm just cutting the title of the button, passing it one parameter of testing.

And then the third one is going to just two parameters. Of course, you can do that by counting the number of colons in that method name. In this case, we are going to pass it two parameters. And we pass it an AppleScript list. And here's some examples of class method. And I'll go through these quickly. So if I wanted to get a hold of the class method called string of NSString, I simply do it this way.

And this is a little more complicated version. And this one's actually kind of cool. It exposes dictionaries to AppleScript. It's called AppleScript Studio. You can actually return a dictionary object, good old NSDictionary, and then you can start playing with it to your heart's desire. You can set keys, get keys, get the values, all that fun stuff. All right. And so we'd like to demonstrate a little bit of this for you. So we'll go back to M1. M1.

Okay, this demo isn't all that flashy, but it sort of illustrates a few points. We're going to go ahead and open it up. Let's sort it. Yep. And we're going to build and run it first. Actually, let's select some code, John. What it does is just a simple application that lets us paste in some text, and then it's going to sort it using a few different means to do so. Because one of the advantages to calling another language is for performance reasons. So we'll go ahead and copy that, and we'll build and run it.

And he simply pastes in this text, and making lists just makes it very simply a list of items, but you can see that it's not sorted. And so we want to make sure our run screen is here. And let's go in and go ahead, and we're going to click on Slow Sort.

Now this is using AppleScript to do the sort. And you'll notice that the other one has AppleScript as well, so I don't want you to think that AppleScript is slow. But what it is, it's really a bad algorithm. It's just a simple bubble sort. So we're going to go ahead and click on that.

And if I can see the monitor down here, it's sorting about 226 items. And it took about, how long, we've got 39, 40, almost 8 seconds, 7 seconds, something about that. So not all that terribly fast for just 262 items. So let's go back in and select some more text. Let's go grab the entire script. And we're going to go back in, we're going to paste that in. And this time, we're going to use a much more efficient-- matter of fact, let's paste it twice.

Because it's a lot of script. We're going to go ahead and execute this. And you'll notice, go ahead and bring up our run window first so we can see it. Oh, no, don't click it yet. There you go. There you go. So it actually does it for you. But go ahead if you like. Make it a list. It'll do the same thing. Go ahead and fast sort it.

This one took about two seconds, so that's quite a, you know, just in a bit of an algorithm. So let's actually take a look at the script that's behind this. And let's go down and look at SlowSort. And let's scroll up just a bit so we can see all of the handler for this.

It's just a simple, very, in essence, brain-dead sort algorithm. But let's take a look at the FastSort, when we click that FastSort button. And it's calling some script that I found out on the web called QuickSort. Now everything he's going to show you from this point on down is all the script that's necessary to execute this QuickSort.

And it keeps going, and it keeps going, and it keeps going, and it keeps going. I was actually extremely pleasantly surprised, for as much script as there was, how fast it actually executed compared to the slower version. But we can do a lot better in this case. And we can add some Objective-C code to our application. So let's quit the app. Let's go into Interface Builder.

And what we're going to do is we're going to add a button to our UI. And let's go ahead and duplicate that one there. Okay. Duplicate that one. There you go. Okay, good. And we're going to call this Fastest Sort. So I'll change the title, make sure it says Objective-C. Want to give proper credit.

And then we're going to name that button in our AppleScript panel. And we're going to call this FastAssort. Okay, and click on the click handler. And this time, we're going to make sure we click on the AppleScript and attach it. All right, let's go ahead and edit script.

Okay, and then we're going to add ourself a new little handler. In the middle of the clicked handler, there's a little test here to see which button was clicked, and then we call the appropriate sort, because from that point on, the rest of the code is the same. So we're just going to simply check to see if it's the fastest sort, and we're going to add a new handler. Let's add that down below our fast sort.

And that's our AppleScript. Simply one line of call method. Sort array with parameter. Now you'll notice in this case, and I didn't talk about this, is that there isn't an of object or of class. And what happens is if you don't provide an object or class, it looks first to the application object. And it says, okay, do you have a delegate? Okay, yes. If you have a delegate, do you handle this method? Yes. Then it will call that method of that delegate.

Now if you don't have a delegate or you can't handle it, then we'll just simply pass it as a method to the application itself. And so that's sometimes the easiest way for us to add this. We're going to add it as a category. So we've got a couple files already pre-built here. Very little code. It's a .h and a .m file. We're going to drag it into our project and add it. And let's take a look at the .h file.

And you can see that it's simply just a category on NSApplication. We just call it sortSupport. And it is a simple method. It takes an array and returns an array, an NSArray. So let's look at the implementation. And all it really does is set up a result to return. Again, it's just a category.

And then it checks to see if we have an array, make sure we have more than one item. Doesn't make sense to sort one item. So actually, there's a bug here. Anybody see it? If there's only one item? Nope. If there's only one item, I'm returning nil. And I should return the array that was passed in.

Good, I found that one. All right, so what it does, it actually calls sorted array using selector. This is a standard foundation in NSString class, and it takes a selector, and there's already a compare method that we can call. And that's it. And so let's go ahead and build and run this.

And let's go copy-- as soon as it's up, let's go copy our source again. And select all of that. And we'll go back into our test and paste it in. And trust me, it sorts when you click the button. That was just as a demonstration. But if you like, go ahead and click Fast Sort. We'll test this one more time. Should we paste it again? Yeah. No, just out-disk it twice. OK, we want it twice. Because we found that this machine's so fast that we had to add a little extra text to make the test interesting.

It does the same thing. Do it one more time. Paste it in. We'll give it the benefit of the doubt. Paste. Make list. Sort. Okay, it's doing, let's see, how many items? 1626, and how many seconds? About two and a half seconds, it looks. Not too bad. Now we're going to try the Objective-C, so let's go ahead and paste it in. Twice.

All right, and this time we're going to call the, go ahead and make a list, don't believe me, and we're going to do the fastest sort of Objective-C. And you can see that it actually did it in just about .4 seconds, so it's quite an improvement in speed. All right, thank you.

Slides, please. Thank you. Actually, we've got to jump back up. Let's go back to demo. I forgot one thing. 1, 2, 4. OK. So that shows just how to do Objective-C. What I would like to show you is an example that ships in AppleScript Studio 1.1. It's called multi-language. Let's go and open that up and show you that we can actually call all of these various languages.

Let's open up our resource file. And again, as far as UI, it's not all that sophisticated. It has a column of buttons and a column of text fields. And when you click on each of these buttons, it fills out the value of that language name. It gets the name from that language and puts it in here. And so let's look at the implementation for the AppleScript one. So we'll go to the AppleScript. Actually, just go to Edit Script.

Or just open up the AppleScript folder there. Which one? AppleScript right there. Open the AppleScript. There you go. And open that one up. And here's the implementation. When you click on the AppleScript button, it simply says, set contents of text field, AppleScript, AppleScript. Well, one can imagine implementation that does that for every button, right? Well, that wouldn't be very useful. So we'll actually take a look at each of these buttons and see what they do. So let's open up-- let's start with a C. And open that one up. And look at the C AppleScript.

And it simply does a set contents of text field to a call method, name for C language. So we're going to look in our .mm file this time. This is actually an Objective-C++ file that we've added to our project. And if we go down to the implementation of that method, name for actually the C language, you'll see that it calls a function that we've added in a C file called getNameForCLanguage.

A couple other things. Let's take a look at this for the Objective-C object, what it does. Actually, let's open up the C file. C.C. C.C. There you go. And let's look at the implementation of this. You can tell it's actually a shipping example because it's got tons of legal stuff here. GetNameForCLanguage returns a simple character array just with the letter C. So let's look at the Objective-C object.

And let's look at the implementation first in the .mm. Now when you choose the Objective-C button, what it does is it calls the call method named for Objective-C. Now this is obviously repetitive. Every one of them does the same thing. So let's close that and look at the .mm file, look at the implementation for that. Note .mm. There you go.

And let's look at the Objective-C language one. Objective-- there you go. OK, good. So what it does is it instantiates an Objective-C object in doing alloc init, auto-release. We're being a good citizen. And then it simply just takes that object and calls name on it. We get the name from the language. And the simplification for it is very simple. We can look at it. We'll skip it for now. Let's look down.

Let's look at the C++. Now, since this is an Objective C++ file, it can actually compile C++ code right inside of our Objective C++ code. And right here, what it's doing is it's constructing a C++ language class that I added. It then will create an NSString, because that's the thing we have to return from this back to AppleScript. And you'll notice that there's a language.name. And so it's simply calling the method on that language, that C++ object, to get its name and returns it.

Now, it's the same thing for the Java language. If we're going through the Java bridge, right below here, you'll see name for Java language. In this case, it uses a function that's built into Foundation called NSClassFromString. And you'll notice that what you do is you provide it the name of the class. And that will give you the Java language object.

It actually allocates it as an Objective C object. And then you can use it just like you did the previous Objective C object. Let's actually look at that one. Let's open up the Java class down in the Java folder. Over in your project. Over here in the project. Yeah, there you go.

And let's look at that. Well, we'll look in the .java file. Okay, so here we've got a .java file in our project, and it simply just defines a simple class, Java language. It has a constructor that just simply signs the data member underscore name to some value, returns that name, and then has these other values in here, and a pen name to string, which we'll show later. So you can see that what it does is it just uses it through the Java bridge. Now, let's look at the java.applescript file.

And you'll notice what it does, it tests to see which button we clicked. Because if we clicked the one that's named Java, it calls the one that we just called. But if I call the direct Java, what it's really doing is it's calling directly into Java. It's not going through the Objective-C bridge or through Objective-C code. I'm just calling right in. I'm instantiating a Java object and calling the method on that handle. And so let's go back into our .mm file.

And let's look at the last one. When you click on all the languages, this one's kind of fun. Because what it does is it creates a mutable string here at the beginning. It creates a C++ object. It creates an Objective-C object. It creates a Java object. And then starting at the very far right, get name for C language, it keeps passing back the result in an append. And so I call every single language, and then I pass that string back.

So let's build and run this. Okay, we'll click on AppleScript. It's very obvious what it's going to do at this point if everything's working. Objective C, C. So that right there just called our C function. The C++ instantiated a C++ object, returned the string. Java went to the Java bridge, direct Java went directly to Java. And the use all, the piece de resistance is to call all of them, and there you go. So it's just that easy to add multiple languages and take advantage of your legacy code and all these other things that you can bring into your project.

Thank you, John. Alright, let's talk a little bit about what you're going to find in Jaguar. Get it right. Get it right. I'm not supposed to say Jagwire. I learned it. We're going to actually, you'll notice that in the Studio version 1.0, 1.1, there's a document-based template. Unfortunately, it doesn't work all that well. And so we're going to vastly improve and make it very, very easy to create document-based applications.

So we should be able to create a text-edit app, I think, in maybe two lines of code, as far as actual script you write. It will be very, very simple. You'll just be asked at the appropriate time, what is the data you want saved in your document? You just simply return the type of thing you want to store, whether it be a string, a list, or a list of records, or any complex AppleScript object that you want. And then when you load the document, you'll get called as an event handler, and you'll be provided with that data that you gave. So just two handlers you'll add to your document object.

And away you go. Now, if that doesn't fill your needs, there'll be two other alternative methods called read from file and write to file. So you can actually get called at the point that that process would normally happen. You don't have to worry about any of the UI. You'll set up all of your document types.

That's all set up in the project. You don't have to worry about it being, you can set the document whether it's dirty or not, but most of the time it's handled for you. It'll prompt for all the right save dialogues. That's all built in and supported. Next thing that we really have heard once in a while on the list is DragonFly.

And that's the fact that we're going to be using DragonDrop because today all you can do is drag some file objects to your application like a droplet. It would be great if we, these are of course not any hard set in stone promises, but we are going to provide some DragonDrop support, as many objects as we possibly can.

So you can drag into text fields or other views or objects and receive notification and get the data from that drag and then do something with that. And in order to do that, we also have to support the pasteboard because that's what's stored in the drag information when you drag on that.

One of my favorite ones, and the thing I'm hoping to get to spend some time on, or that we're going to spend some time on, is the data source improvements. And those of you that have used Studio found that the table adding data to a data source that gets populated in a table isn't as fast as it possibly could be. And we've put out some support code, some Objective-C code, to make that much faster.

So for instance, hopefully, we'll build it right into AppleScript so you don't have to call any Objective-C code. So you can do something like take a list of records and simply add it to your data source. With one line of code, it'll quickly populate your data source, and away you go.

Now things that are a little further out ahead that we're looking at is talking about a script property. We want to be able to have you at runtime actually get the script of the UI object or set the script so that you can dynamically change these things on the fly. It solves a lot of problems for us and something we're very excited about.

Now that's sort of all the runtime things that we want to work on. There are also development side things. We want to vastly improve the dictionary viewer. It would be great if you could, for instance, select some term in your script and have it go look it up in the dictionary viewer for you or help.

There's a lot of things we want to do there. An object hierarchy viewer right in your applications so you can see all of your objects and see the attributes of that object. We're also really, really excited about web services and what that means for us and what we can do so that you can create some really compelling applications. And so we're going to be working on better ways. A lot of what we're going to leverage off of the work that's being done at the web services.

Client framework level. We're going to build off of that and add better things on top of it. And the last one which is sort of really out there is other OSA languages. There are people that actually want to build Apple Script Studio apps in Python or Perl. And as long as they can provide an OSA component, it's something that's within the realm of possibility. And so we'll look at trying to do those type of things. At the moment, with Studio 1.1 that just shipped last week, it's in your development. It's in the developer CD. It's in the release notes.

There's actually a defaults write that disables the auto generation of the Apple Script when you're in an interface builder. I had somebody send me an email saying, "Well, I wrote this Python thing, but the problem is every time I went into IB, it generated Apple Script in my Python file." So at least we sort of got out of his way so he could do whatever else he'd like to do.

[Transcript missing]

And this is the roadmap. Of course, we had our AppleScript update this session this morning. I actually learned a few things myself, which is great. I'm very excited about SDEFs. AppleScriptKit is going to take very quick advantage of SDEFs, so that I only have to write in one file and not 18 pairs of all these suites. It's going to be a great thing. We have our feedback forum tomorrow at 3.30.

I look forward to having you there. The Cocoa scripting, which I highly recommend, because we leverage everything off of foundation scripting. If you're interested in the Objective-C or Java side, go to that session. If you're new to Project Builder, make sure you check out the Project Builder ID.

And this is who you can contact, Jason Yeo and myself. Feel free to send me an email. And then my manager, Chris Espinosa. And with that, there's also one other thing, if you want to get some more information, check out the Studio website. This website is going to grow in the future. It's hopefully the place we're going to be using as a repository for great examples of Studio applications. And the one I recommend most is to get on the AppleScript Studio mailing list.

We monitor it as much as possible. We answer as many as we can. It's a great resource. There's starting to be a community that's developing that are starting to help each other, which is wonderful. And then there's also the documentation can be found. The slide is incorrect. It should be uppercase D, uppercase E at AppleScript Studio.