Learn AppleScript - your recommendations?

Discussion in 'Mac Programming' started by sergiobaschi, Dec 2, 2013.

  1. sergiobaschi macrumors regular

    Joined:
    Nov 30, 2012
    Location:
    Gothenburg, Sweden
    #1
    I've decided to learn AppleScripting. I've done some very basic scripts, such as on start up, connect to server X and Y, open this website etc etc, but want to go deeper.

    I've found this book. It's almost 6 years old, so I'm thinking there must be something newer out there?

    If you have any recommendations, please let me know.

    (I am not a professional developer, but know Objective-C, Java and Javascript on various levels.)

    Thank you for any input.
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    I'm curious - what makes you think there's more to learn? What do you want to do with it that you can't already do?

    AppleScript was created with the intent of being a basic scripting language that anyone, even people who don't know any other programming languages, could pick up quickly.

    Further, I think Apple has pretty much abandoned it. Automator has kind of replaced it.

    Just reading a book doesn't teach you languages - using a language teaches you it. I'd suggest coming up with something you'd like to do then, if you can't do it on your own, asking.
     
  3. sergiobaschi thread starter macrumors regular

    Joined:
    Nov 30, 2012
    Location:
    Gothenburg, Sweden
    #3
    Naturally I can just stop by here and ask every time I encounter a problem. (That's how I've learned Javascript and HTML.) But at this moment, I think it's more time efficient to get deeper knowledge by doing some studying.

    Basically: when I learned Javascript, I learned that document.write('hello');
    wrote "hello". But I didn't know why I had to write out "document". Things like that.

    What I would like to be able to do:
    I want to be able to add more logic to the programming. I want to learn about if:s and loops and how to use arrays and how to store information, temporary and over time.

    More practical examples of what I would like to be able to do:
    I don't want to connect to the server if I'm using wifi, or if I'm already connected to the server.
    I don't want to open a specific web page if the web page's already open. I don't want to open a web page at all, if I don't have any internet connection.

    Also I want to use AppleScript in Indesign, to create some time saving scripts. At work we're dealing with magazines in over 50 languages, and to be able to automate some of the Indesign translation work would save us hours each month.
     
  4. Red Menace macrumors 6502

    Red Menace

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #4
    There is always the AppleScript Language Guide - a PDF can be downloaded for local reference and the document contents are also available in Xcode if you have that installed.

    AppleScript is still a long ways from being abandoned - AppleScriptObjC/Cocoa-AppleScript is continually being improved, and script libraries were added in Mavericks.
     
  5. bumper314 macrumors member

    Joined:
    Jun 23, 2009
    #5
    I love AppleScript. It's a quirky little language, but immensely powerful when you start leveraging other applications to do work (process images, text, etc).

    I learned AppleScript from the O'Reilly book, but it's been so long I can't remember if it was any good. However, all the content is still relevant as the language hasn't changed much in 20 years(citation needed).

    If you really get into AppleScript, I totally recommend Script Debugger. I still use Version 4.5, so I can't comment on the new version 5.

    I also recommend FastScripts for binding shortcuts to AppleScripts or just seeing a contextual list of scripts based on the active application. For example, I have Safari AppleScripts to download all my banks statements, convert the current URL to Markdown and put it in the clipboard, etc. You can do some fun stuff with Safari via AppleScript's "do JavaScript" function.
     
  6. Mark FX macrumors regular

    Mark FX

    Joined:
    Nov 18, 2011
    Location:
    West Sussex, UK
    #6
    As Red Menace has eluded to, the latest trend is to learn the ApplescriptObjC language, which can be written using the Applescript Editor, or from the project template that comes with Xcode, where you can build full UI projects with Inteface Builder, and access any Cocoa Framework that is based on the Objective-C language, as well as being able to use traditional vanilla Applescript in combination.
    Unfortunatley Apple have been a bit slow with coming up with any comprehensive documentation on the ApplescriptObjC language, but there are two very good books written by Shane Stanley, which represent the only detailed info on this latest and more powerful version of Applescript.

    http://www.macosxautomation.com/applescript/apps/everyday_book.html
    http://www.macosxautomation.com/applescript/apps/book.html

    As for Apple abadoning Applescript, that's very much not the case, but they are trying to change the direction of the Applescript language, encouraging people to use Automator for automation tasks, and to use ApplescriptObjC to build the more traditional utility type applications.

    Hope you find this information useful.

    Regards Mark
     
  7. sergiobaschi thread starter macrumors regular

    Joined:
    Nov 30, 2012
    Location:
    Gothenburg, Sweden
    #7
    Thank you - this is exactly what I was looking for.

    I have some knowledge in Objective-C, so I'll definitely check that out.
     
  8. sergiobaschi thread starter macrumors regular

    Joined:
    Nov 30, 2012
    Location:
    Gothenburg, Sweden
    #8
    I just made a script that will run every day, that logs on to my bank's website and checks how much money I have on the account connected to my VISA card. If the sum is less than 4000 SEK, then it makes a transfer of the difference. It's like an auto refill! :)
     
  9. Mark FX macrumors regular

    Mark FX

    Joined:
    Nov 18, 2011
    Location:
    West Sussex, UK
    #9
    Yeah Applescript is awesome.

    And a lot more powerful than the serious developers give it credit for, and as a serious Objective-C developer I cant help using it on a regular basis.

    Let's hope Apple continue to support it, and continue to improve the ApplescriptObjC language, which will give the beginner and novice coders an introduction to programming, before they are encouraged to move on to the more powerful Objective-C language.

    Regards mark
     
  10. hhas macrumors regular

    Joined:
    Oct 15, 2007
    #10
    Note that AppleScript-ObjC is a bridge between the AppleScript and Objective-C runtimes, not a language itself.

    Also, AppleScript is a lousy language for learning to program: convoluted, buggy, obfuscated, and wildly inconsistent, riddled with 'magical' behaviors and traps for the unwary; a complete mess. The one really good reason for learning AS is if you wish to automate your desktop, as it's the only supported option which can speak Apple events correctly, so if you can wade through all the crap then it can be excellent for that. Otherwise, I'd recommend going elsewhere.[1]

    --

    [1] Unfortunately, finding good, popular, beginner-friendly languages to recommend is not so easy: mainstream scripting languages like Python, Ruby, and JavaScript are stupidly over-complicated, and I can't think of any modern LOGO-style languages that are particularly popular with a good spread of libraries.
     
  11. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #11
    I don't think that's fair, if you use it for it's intended purpose, automation in the gui layer on OS X.
     
  12. hhas macrumors regular

    Joined:
    Oct 15, 2007
    #12
    Of course it's fair: the language is a mess.

    While the underlying concepts are actually pretty straightforward [1], they're buried beneath a morass of well-meaning but misguided obfuscation and two decades of accummulated cruft and crud, making it far more confusing and complicated than it ever ought to be.

    It just happens to be the least awful option still available to users who wish to automate their desktop apps; though as a rule of thumb, the less they try to understand it, the happier they will be.

    --

    [1] Simple imperative, procedural interpreted language interpreter largely comparable to JavaScript (though less dynamic), with embedded Apple events bridge that allows it to construct simple relational-style queries and dispatch remote procedure calls, and packaged as a Component Manager component. Everything is bodge and botch.
     
  13. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #13
    My point is I always looked at it as a very domain specific language, for simple automation tasks, not something that is general purpose or aimed at being extensible, or building complete "Applications" with. That's why I thought the comment wasn't fair, because it didn't really take that into account. Having said all that, I don't really know much Applescript at all.
     
  14. hhas macrumors regular

    Joined:
    Oct 15, 2007
    #14
    It's a general purpose language with some domain-specific extensions. None of which excuses it being a right mess in both design and implementation. Compare to something like LOGO, another general purpose end-user language with some domain-specific extensions. LOGO is the absolute model of clarity, parsimony, and accessibility: you can grasp all the language concepts in under an hour. (LOGO was designed to be easily learned by six to eight year olds, yet as a stealth Lisp is powerful and flexible enough for teaching college level Computer Science.)

    Working out exactly what makes AppleScript tick requires an unholy amount of learning, guesswork, blood, sweat, and trial and error. The only guarantee is that any time you think you've truly grasped how it works, you almost certainly don't. The best way to get on with AppleScript is not to even try to understand it - you hurt yourself much less that way. :p

    See the sig. :) Several hundred pages just to explain how this supposedly 'simple' language works - and even then I had to fudge, fib, or ignore a lot of the fundamental details just to avoid completely traumatizing readers.[1]

    --

    [1] I have a basic rule that if you can't explain something clearly and concisely, redesign it so you can. Needless to say, I develop and train my own AppleScript replacements now.:)
     
  15. Rich.Cohen, Dec 17, 2013
    Last edited by a moderator: Dec 17, 2013

    Rich.Cohen macrumors regular

    Joined:
    Oct 28, 2013
    Location:
    Washington DC
    #15
    I was in your position about 3 years ago. I bought three books and compared them. The one I liked best was Learn AppleScript, now in the third edition by Hamish Sanderson and Hanaan Rosenthal. I preferred its index to the others. I still use this book regularly.

    You should also know that there is a forum devoted exclusively to AppleScript: http://macscripter.net They are very helpful and have a useful archive.

    I agree with those who say that AppleScript is a quirky and sometimes difficult language. However it does work and it lends itself well to a lot of quick and dirty tasks. I suspect that there may be a memory leak problem for very long-running scripts.
     

Share This Page