Thursday, July 24, 2014

#1 2012-12-05 02:36:20 pm

Monostratos
Member
From: Denmark
Registered: 2010-06-20
Posts: 35

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


Filed under: guide

Offline

 

#2 2012-12-05 06:47:16 pm

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4631

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

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


iMac & MBP both running OS X 10.9.1

Offline

 

#3 2012-12-06 03:43:19 am

rpvermeulen
Member
From: Rotterdam, Netherlands
Registered: 2011-04-23
Posts: 23
Website

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

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!


Rob Vermeulen
Rotterdam, The Netherlands

Offline

 

#4 2012-12-06 04:30:38 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 1852

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

Great work!

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

When someone is already an experienced programmer he would write

Applescript:

if someBoolean is true then
if someBoolean is false then

down as:

Applescript:

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:

Applescript:

--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!")


Kind regards

Offline

 

#5 2012-12-06 04:43:44 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3521

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

rpvermeulen wrote:

Currently we are enjoying so many excellent Danish tv-series

And you are not alone in that...


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#6 2012-12-06 05:48:34 am

Monostratos
Member
From: Denmark
Registered: 2010-06-20
Posts: 35

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

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.

Offline

 

#7 2012-12-06 05:55:04 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3521

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

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#8 2012-12-06 05:58:00 am

Monostratos
Member
From: Denmark
Registered: 2010-06-20
Posts: 35

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

Shane Stanley wrote:

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.

Offline

 

#9 2012-12-06 06:01:39 am

rpvermeulen
Member
From: Rotterdam, Netherlands
Registered: 2011-04-23
Posts: 23
Website

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

Monostratos wrote:

By the way which TV series are you think of? I haven't seen any Danish television for years.

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


Rob Vermeulen
Rotterdam, The Netherlands

Offline

 

#10 2012-12-06 06:04:05 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3521

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

Monostratos wrote:

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

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#11 2012-12-06 06:06:54 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3521

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

rpvermeulen wrote:

Forbrydelsen, Livvaktene, Borgen...

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#12 2012-12-06 06:34:55 am

Monostratos
Member
From: Denmark
Registered: 2010-06-20
Posts: 35

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

Shane Stanley wrote:

Monostratos wrote:

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

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.

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

Offline

 

#13 2012-12-06 02:27:41 pm

SuperMacGuy
Member
From: Amish Country, Lancaster, PA
Registered: 2004-06-23
Posts: 416
Website

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

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.


Scripts for InDesign: http://chris.paveglio.com
ASOC & Cocoa, specializing in InDesign, Photoshop, Ai, FileMaker

Offline

 

#14 2012-12-06 05:52:29 pm

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 1852

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

Monostratos wrote:

@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!

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


Kind regards

Offline

 

#15 2012-12-06 09:40:23 pm

McUsrII
Member
Registered: 2012-11-20
Posts: 2254
Website

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

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!  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.

Last edited by McUsrII (2012-12-07 02:12:16 am)


Filed under: applescript

Offline

 

#16 2012-12-07 04:25:41 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 1852

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

McUsrII wrote:

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!  smile

Monostratos wrote:

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 think the whole point of Monostratos is to avoid the AppleScript Language Guide for people who have already programming experience.


Kind regards

Offline

 

#17 2012-12-07 04:34:03 am

McUsrII
Member
Registered: 2012-11-20
Posts: 2254
Website

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

DJ Bazzie Wazze. wrote:

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! smile

Last edited by McUsrII (2012-12-07 04:35:45 am)


Filed under: ASLG, Definitive Guide

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.029 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)