Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

javabear90

macrumors 6502a
Original poster
Dec 7, 2003
512
0
Houston, TX
I've been looking into doing some programming and I was just wondering, whats the deal with apple script?
How easy is it to use?
What is it good for?
etc....
Thanks,
-Ted
 
Applescript was designed to be very human like in syntax. It is also very lenient. Eg you could say 'set x to result of...' or 'set x to the result of...'. In terms of languages, it is probably one of the easiest to learn before of it's leniency and human like syntax.

Its uses are not so great however. Basically it was designed to control other applications, eg you could have a script to make a playlist in iTunes. It was not designed for making standalone applications. Applescript Studio in Mac OS X is a step towards this, but is still a long way off (I'm not sure about the details of Applescript Studio though, I haven't used it).

If you want to get into real programming, Mac OS X includes Objective C compilers and Java compilers. It's a steep learning curve if you're a beginner though. Applescript is a good introduction to a few programming concepts but if you're interested in making standalone applications you'll find its limitations very quickly.
 
javabear90 said:
I've been looking into doing some programming and I was just wondering, whats the deal with apple script?
How easy is it to use?
What is it good for?
etc....
Thanks,
-Ted

AppleScript is especially useful for controlling other apps, but it can be used to do things like manipulate files, do calculations and generally control the system too. Simple AppleScripts can't do much in the way of UI (just some built in dialogs and file chooser stuff.) so it depends on what you want to do if that is good enough. But AppleScript is the *only* way to do certain things when it comes to combining services from a number of different apps and creating a custom solution.

With AppleScript Studio you can create fully featured applications. It's not quite as powerful as something like Carbon, Cocoa or even Java, but you can create fully featured GUI applications. Plus you can call through to Objective C code contained in the Studio app (and therefore indirectly to C/C++/Java) and call command line tools and scripts for support services to do nearly anything possible with the system. It's actually quite amazing how it all can play together.

I think it is a bit elitist to say that it is not 'real' programming as implied by the earlier post. Of course it's 'real programming'. It may not be as powerful and not as fast running as native 'compiled' apps, but it can be more than adequate for many things, and much simpler to develop certain kinds of applications than using compiled languages. It's like sometimes it is much easier to use something like awk than it is to write a C tool to do certain things. Everything has its place.

For instance, there are many Studio apps that have been developed to put UIs on top of command line tools. In those cases, the command line tool does the heavy lifting, and the Studio app is a very easy way to create a UI (using Interface Builder) and hook up buttons and such for triggering the actions, entering form data or whatever. You can even control playing audio files, QuickTime movies, even show web pages within a Studio app. You can get very sophisticated with Studio apps. I have written many of them even though I am a seasoned C/C++/Java/ObjC programmer. It's just so easy to hook up basic UIs and write a few lines of code to dispatch actions either to pure AppleScript handlers, or to extended services through other scriptable apps, to a shell script or to ObjC code. I even have a few Studio apps that are thousands of lines of code.

So, don't be put off by people that say AS is not 'real programming'. Play with it, use it and learn where it is truly your best choice for a given task. It can be a starting point to learn other languages by extending it with the Objective C bridging mechanism.
 
huckleup said:
I think it is a bit elitist to say that it is not 'real' programming as implied by the earlier post. Of course it's 'real programming'. It may not be as powerful and not as fast running as native 'compiled' apps, but it can be more than adequate for many things, and much simpler to develop certain kinds of applications than using compiled languages. It's like sometimes it is much easier to use something like awk than it is to write a C tool to do certain things. Everything has its place.

I didn't word my post very well did I. Yes it is real programming, what I meant to say was it doesn't have the power of most languages, especially its lack of UI in the past. Apparently Applescript Studio is a lot more powerful than I thought, so I was partly wrong there.

Applescript was the first language I used, and it was a very useful introduction to programming. After I while I had to move on when I wanted to do more things with a GUI, and more speed. Applescript itself has come a long way since I last used it so much though, so that was probably the source of my antiquated views. I still use it occasionally though, and for what I use it for it is very powerful. It allows you to quickly create powerful productivity scripts among others. It is very useful in scripting other applications, which you typically cannot do in other languages.
 
Can anybody recommend a good source for learning AppleScript, especially its more advanced uses?
 
O'Reilly just released a new book--AppleScript: The Definitive Guide which gives more of a programmer's aspect on it. There are also books from Peachpit Press and Sam's that are really good for beginners.

While I'm just starting, I find AppleScript good at doing some quick and dirty interaction with the user and manipulating the system. I can do things with GUI that would normally end up as a shell script with poor results due to mistakes in typing. The worst thing (as with most things Apple since Mac OS X) is the documentation or lack of same.
 
Try this one
http://www.amazon.com/exec/obidos/t...558283307/all/ref=dp_pb_a/002-3107824-9508049
scroll to the bottom

I bought it for $34.95 a couple of years ago but it is still very good for resource and it starts at the beginning with "What is Scripting?"
The book is 877 pages and comes with a CD (if you get the one on Amazon, its going for $19.95 w/sealed CD)
I was going to attach a PDF of the T.O.C. but I couldn't get it lower than 132k so just trust me ;)
 
As an Amazon Associate, MacRumors earns a commission from qualifying purchases made through links in this post.
mms said:
Can anybody recommend a good source for learning AppleScript, especially its more advanced uses?

There are some good basic AppleScripts available in the Scripting menu. Looking at those can get you started.

There's a bunch of essential info at the Apple developer site at:
http://developer.apple.com/documentation/AppleScript/

At the developer site you will find some more examples, the language spec, and some guidance of where to go for more info. The references are essential so that you can look up things, but they won't help a beginner to get started much. At some level, there is almost too much information, and it is easy to get lost in it. But it has improved in the past few years.

Buried in that site is a link to 'Creating an AppleScript Studio Application'. I personally think that tutorial is way to complicated for beginners. They should have a much more tiered approach to help people get started.

For AppleScript Studio there are some good examples in the /Developer/Examples folder. Unfortunately many of those are also 'over the top' as far as I'm concerned. Many of them are very complex, and try to enforce a very strict academic programming model called MVC (Model-View-Controller). Though I am a fan of MVC, I have been studying programming for many years, and it is a good advanced concept. But for beginners, and probably even most of the target audience of AppleScript, I think it is just way too intimidating. Again, I think they have some good examples in there too, but it can be daunting for a beginner to just open one at random, see one of the real complex ones, and then just run away. I think if they grouped the examples in some way like Basic/Intermediate/Advanced, it would help with the initial impression factor.

Some of the examples are a bit easier to digest than others. Like the Archive Maker one shows a lot of features, but is pretty will structured in a way that you can learn gradually from the individual handlers, and not have to have such a broad conceptual understanding of a complex intertwined system as in the examples that utilize the MVC approach. Some of the examples are very simple, showing only how to do one thing, like how to use tables or drawers or some specific thing. I would recommend quickly looking thorough all of them and see if any 'talk to you'.

I think Apple has a history of making cool technologies like AS and not finding a good way to reach the broad target audiences with their documentation and examples. AppleScript has been around for many years, with its roots in HyperCard/HyperTalk. Most people have never even tried any AS at all, and that's really a shame. There are plenty of real basic things that almost anyone could do to help automate things and create custom solutions to their workflows.

Maybe some of the books mentioned will talk to more people. But I think Apple needs to be doing much more to get it into people's hands and minds, because few people will go out and buy a book about something they don't even know exists or think they need to know about.
 
on the same subject (sorry) but is there any software that i can make this kind of stuff with? or am i being lazy, and applescrit is the easiest?
 
on the same subject (sorry) but is there any software that i can make this kind of stuff with? or am i being lazy, and applescript is the easiest?
 
I'm currently developing an AppleScript Application for a professor at my University. Right now, I'm trying to find out how to get an Open box to work with it so I can select a certain movie...


AppleScript is unique in what it can do to connect several applications, such as QuickTime and Filemaker. It's easy to learn, and can be very useful for many things...
 
G4scott said:
I'm currently developing an AppleScript Application for a professor at my University. Right now, I'm trying to find out how to get an Open box to work with it so I can select a certain movie...

You can use 'choose file'. See the Standard Additions dictionary for options like setting a prompt and setting filtering to show only certain types of files.

Of course you will need to call that in some handler called by the action of some UI element like a button or menu item. Is that where you are stuck?
 
thejazzman10 said:
on the same subject (sorry) but is there any software that i can make this kind of stuff with? or am i being lazy, and applescript is the easiest?

I don't understand your question.

Are you asking is there some *other* way to do this other than AppleScript? Of course - there are all kinds of other development environments and languages.

Are you asking what tools do you use to create AppleScripts? You can use the Script Editor for simple scripts and Xcode for AppleScript Studio applications.

Script Editor and Xcode are free. Plus you can always develop with the command line tools like gcc. There are also lots of other free and commercial tools available.

What was the question again?
 
huckleup said:
I don't understand your question.

Are you asking is there some *other* way to do this other than AppleScript? Of course - there are all kinds of other development environments and languages.

Are you asking what tools do you use to create AppleScripts? You can use the Script Editor for simple scripts and Xcode for AppleScript Studio applications.

Script Editor and Xcode are free. Plus you can always develop with the command line tools like gcc. There are also lots of other free and commercial tools available.

What was the question again?
i was just wondering if there was a way to make scripts & such without having to learn all of this complicated "languages". Thanks!!
 
thejazzman10 said:
i was just wondering if there was a way to make scripts & such without having to learn all of this complicated "languages". Thanks!!

In the Script Editor (Applications -> AppleScript) there is a record feature. Click it, and it should script out your actions. Now I have never gotten this to actually work, but other people have so YMMV.
 
DavidLeblond said:
In the Script Editor (Applications -> AppleScript) there is a record feature. Click it, and it should script out your actions. Now I have never gotten this to actually work, but other people have so YMMV.

Actually, very few applications are recordable. Making an app recordable is a lot of work, so it doesn't happen much. Most are scriptable, but that is a totally different thing. Making an app scriptable is not that much work, so most apps support it at least to some degree.
 
thejazzman10 said:
i was just wondering if there was a way to make scripts & such without having to learn all of this complicated "languages". Thanks!!

Scripting is not necessarily complicated. Some scripts are simple one-liners. Others can of course be much more complicated. As stated numerous times in the previous posts, it totally depends what you want to do.

I think it would be best for you to now move beyond abstract question mode and start asking something like 'how best to do this specific task'. Then people can direct you towards the best way to do it. Speaking too generally is mostly going to just be a dead end.

If you can state a specific need, it is likely that someone can tell you 'just do this'. You don't need to learn how to write scripts to use them. Over time you may get motivated to start writing your own scripts as you start to see how they are formed, and how useful it can be to know how to make your own.

You get out of it what you put into it. So, to use your words, yes, I think you are being a bit lazy. :p
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.