AppleScript

Discussion in 'Mac Apps and Mac App Store' started by javabear90, Mar 18, 2004.

  1. javabear90 macrumors 6502a

    javabear90

    Joined:
    Dec 7, 2003
    Location:
    Houston, TX
    #1
    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
     
  2. HexMonkey Administrator

    HexMonkey

    Staff Member

    Joined:
    Feb 5, 2004
    Location:
    New Zealand
    #2
    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.
     
  3. huckleup macrumors member

    Joined:
    Feb 6, 2003
    Location:
    Left Coast
    #3
    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.
     
  4. HexMonkey Administrator

    HexMonkey

    Staff Member

    Joined:
    Feb 5, 2004
    Location:
    New Zealand
    #4
    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.
     
  5. mms macrumors 6502a

    Joined:
    Oct 8, 2003
    Location:
    CA
    #5
    Can anybody recommend a good source for learning AppleScript, especially its more advanced uses?
     
  6. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #6
    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.
     
  7. Sparky's macrumors 6502a

    Sparky's

    Joined:
    Feb 11, 2004
    #7
    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 ;)
     
  8. huckleup macrumors member

    Joined:
    Feb 6, 2003
    Location:
    Left Coast
    #8
    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.
     
  9. thejazzman10 Guest

    #9
    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?
     
  10. thejazzman10 Guest

    #10
    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?
     
  11. G4scott macrumors 68020

    G4scott

    Joined:
    Jan 9, 2002
    Location:
    Austin, TX
    #11
    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...
     
  12. huckleup macrumors member

    Joined:
    Feb 6, 2003
    Location:
    Left Coast
    #12
    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?
     
  13. huckleup macrumors member

    Joined:
    Feb 6, 2003
    Location:
    Left Coast
    #13
    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?
     
  14. thejazzman10 Guest

    #14
    i was just wondering if there was a way to make scripts & such without having to learn all of this complicated "languages". Thanks!!
     
  15. DavidLeblond macrumors 68020

    DavidLeblond

    Joined:
    Jan 6, 2004
    Location:
    Raleigh, NC
    #15
    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.
     
  16. huckleup macrumors member

    Joined:
    Feb 6, 2003
    Location:
    Left Coast
    #16
    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.
     
  17. huckleup macrumors member

    Joined:
    Feb 6, 2003
    Location:
    Left Coast
    #17
    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
     

Share This Page