I'm writing a crash course in AppleScript for programmers. Feedback?

Greetings scripters.

You’ve helped me often, and I thought I would do my part for the community by writing a short crash course in AppleScript for people who already have some coding experience from a different language. I know there are already a lot of good tutorials around here, but most are very specific and detailed. I haven’t found a quick and dirty guide to the syntax for someone who doesn’t want to learn the entire language in all its wonderful details, but just needs to know the syntax for a little piece of automation he/she needs.

If you have feed-back I would be happy to hear it.

Link: AppleScript for Programmers

One of the mysteries for first time coders is how to read a dictionary.

Hej, I’m very interested! Currently we are enjoying so many excellent Danish tv-series - you guys know how to tell a story :wink:

Be sure to include the differences between language, framework en development tool; that’s what I see a lot of confusion about. And it won’t be easy to crash-teach thinking objects.

It also might be a good idea to think about what exactly you want to help beginners with: translating ObjectiveC into ASOC, or ‘Xcodifying’ Applescript. As a beginner I find myself constantly switching between these two ways of thinking.

Good luck!

Great work!

I have some suggetions, please, don’t see them as criticism.

When someone is already an experienced programmer he would write

if someBoolean is true then
if someBoolean is false then

down as:

if someBoolean then
if not someBoolean then

Also I would keep globals in the variable chapter and mention properties there as well.

Also I would mention the usage of parentheses which can be very useful like:

--code will only quote "Hello World!" 
quoted form of "Hello World!" & return & "Goodbye!"
--now the entire string will be quoted
quoted form of ("Hello World!" & return & "Goodbye!")

And you are not alone in that…

D’oh! Sorry, I meant to post this in the general AppleScript forum. If someone can move it there, I’d appreciate it. There’s already a lot of great feedback so it would be a shame to delete and resubmit.

@DJ Bazzie Wazzie: I do mention the briefer way of checking booleans in the example right after the one you mention. You’re right about globals, properties and parentheses - thanks!

@Adam Bell: So true. I tend to avoid those myself, too. I guess this is a good excuse to read up on that topic.

@rpvermeulen: I made a mistake when I posted in this forum. Actually I don’t plan on writing about ASOC at all, except maybe mention its existence and link to Shane Stanley’s ebook. By the way which TV series are you think of? I haven’t seen any Danish television for years.

One of my pet hates: equating coercion via the “as” keyword with casting. They really are quite different things.

This is news to me. Would you mind explaining? I’ll be happy to edit the paragraph.

Forbrydelsen, Livvaktene, Borgen… (this is very much off topic, sorry folks, but everyone should now about the reinvention of tv drama by the Danish…)

A cast is generally just a reinterpretation of a bit pattern, at least in explicit cases, whereas a coercion is a full-on conversion. Something like “42 as text” is not like a cast.

Alas, we are yet to get ‘Borgen’. And you forgot ‘Bron | Broen’, which is part Danish.

I’m still not sure I understand the difference. Isn’t the result more or less the same even though the process is different? I’ll edit the chapter heading to read Coercion in stead, and mention that it’s almost, but not quite, entirely unlike casting (to paraphrase Douglas Adams).
Thanks for taking the time to do this.

Morten

I like to stress that Applescript is a peek into the API/base programming of each application. And every 3rd party app implements custom functions differently. For example, Interarchy (FTP) doesn’t have the same keywords as CyberDuck (FTP) and achieve their goals in completely different ways. So scripting apps can be sometimes easy or sometimes very difficult/downright Byzantine, for example Apple Mail is notorious for difficult and near impossible tasks that appear to be super simple from a user perspective.

I would highly recommend Shane’s book as required and also Matt Neuberg’s book as required reference for a serious scripted, or side-reading.

Thank you! Also sorry cause you’re right, I have read the article too fast, my mistake about the boolean use in expressions.

A good tip in your book would be to state that AppleScript Language Guide is the first book, after that they should read, or refer to sections in it directly! And get rid of the kittens. (I hope they transform into tip boxes over time! :slight_smile:

Other things I’d like to see would be:

Debugging, logging facilities

This is imporatant when starting with AppleScript to overcome hurdles.

Like other languages, it needs logging facilities, so you don’t fumble in blindness. Things may differ when run stand alone, than in the editor, as the environment is different.

log, and handlers that log to the console, when run from an app or as a script.

Usage of Xcode for development, if you can’t afford Script Debugger, which you should

If you manage to do that, I don’t unless I do something in ASStudio or ASObjC, which I don’t at the moment, but then I get the ability to step through code. and inspect variables in the debugger, not a replacement for Script Debugger, which is the singular most important thing to buy/have, in order to get up to speed.

Edit

The usage of try on error end try for catching errors, either with a blunt log statement inside when run from the ScriptEditor, or passing the error number and message over to a dialog box, or sending it to a logfile, (you can make Console.app pop up when there are errors), is very useful. Reading and understanding the error messages too.

I think the whole point of Monostratos is to avoid the AppleScript Language Guide for people who have already programming experience.

I see the need for a good entry. But it is with it AppleScript Language Guide, like a C-programming manual. You can’t really avoid it.

But you need the definitions, and AppleScript Language Guide, is readable, and has at least some good examples, before you buy the Definitive Guide by Matt Neuburg, which it takes some experience to consume anyway, it is like the Annotated C Standard Library for Applescript.

AppleScript doesn’t bear that much resemblance to regular programming languages, so I think that the Language guide is good to have, for definitions and such, with small examples. It is also easy to search in it with Preview, and it is free.

There is no free lunch, even if AppleScript is a little language, you better eat the vegetables! :slight_smile: