Tell Blocks and Variables (Applescript Tutorial 1)

Hey guys,
I’m making a series of Applescript Video Tutorials, and I figured what better place to share them then MacScripter? Heres the link (http://www.youtube.com/watch?v=EpyXM90kRR4). If you guys have any comments/questions/suggestions please post them below! Thanks,

~Josh Fletcher

First of all I like the idea of having tutorials about AppleScript like Craig did for AppleScriptObjC but in this movie I felt like it wasn’t detailed enough also the first tutorial about applescript shouldn’t be about tell blocks at all. First you talk about syntax like if-then, loops, properties, standard classes like text, character, file, folder, alias, integer, number, real, list and record for instance. The next step would be discussing handlers, how to subclass them and script objects. Knowing these you can start talking about scoping (focus on objects in the parenting chain), application scripting and then you can discuss tell blocks with it and when to use it or not (also missing in the movie).

It’s just my opinion and like I said I like the idea of having AppleScript tutorial movies on the web.

A few things occurred to me.

You should start by explaining what AppleScript is:

  1. That it’s a “scripting” language for automating tasks and workflows on a computer.
  2. That it can do some things itself, but usually tells other software what to do (if that software will listen).
  3. That the basic language is quite small but can be extended by means of “scripting additions” (aka “OSAXen”, which of course have to be present on any computer compiling or running scripts which use them) and by scriptable applications having their own commands and features (and to some extent their own variations on the syntax).

You should use the correct AppleScript terminology from the beginning ” eg. “text” and “list” ” only using “string” and “array” to explain the equivalence to people coming to AppleScript from other computer languages.

Depending on how much programming background you’re assuming in your target audience, you could explain what a variable is when you first use it. Also, usefully, the difference between a variable and the value it contains.

Something which wouldn’t have occurred to me before I watched the video is that ‘beep’ actually plays the user’s preferred alert sound, which isn’t necessarily a beep!

This is a little more advanced, but I would also appreciate if you clarified how AS commands to 3rd party apps work. I believe for newbies, they see AS as a way to control an app, and often are confused as to why some language works in app A but similar commands don’t work in app B. I know I was.

But my revelation was finally (after reading Neuberg’s book) this: Applescript (in 3rd party apps) is a simple way to replication/control THE NATIVE COCOA FUNCTIONS AND MANIPULATE DATA of the app. Different applications will implement their internal data in different ways, and implement their methods to do things in different ways.
So for example InDesign’s “export a PDF” method and QuarkXPress’s “export a PDF” do not work the same, do not take the same parameters, and completely do not run the same functions inside the app. They both might produce a PDF file for you, but you must look at each app’s dictionary to find out how to ask the app to export the PDF.

When you are frustrated by not being able “to do something simple” or think “why doesn’t this work?”, remember that you might need to do some serious investigation into the commands of the app. Some apps can have very convoluted ways to do something that is very simple in the UI. You could think of your role making some scripts as reverse engineering the internals of some application, and no 2 apps will implement things the same. And sadly, sometimes functions you think are rather important or are “very simple and ought to be scriptable” just are not. And you have to contact the app developer to see if scripting can be included (and some apps simply are not scriptable at all).

In Neuberg’s book, p485 section “A Day In The Life” was extremely enlightening.

Bazzie Wazzie,
I understand your concern for the way I went about teaching applescript in this first tutorial. However, I wanted to jump right into the application scripting portion of Applescript for two reasons. Firstly, the tutorial would have been long and horribly boring if all I had discussed was the properties of variables (I know when I was first starting applescript I wanted to get right into controlling the OS and applications), and secondly, as Nigel says, one of the main reasons for using applescript is for its control over applications and for that reason as well, I wanted to immediately go into application scripting. Personally, I learned all of the applescript I know from both script snippets I’ve found on google and the applescript dictionaries. For that reason, the overall purpose of the whole string of tutorials I am going to create will solely be to teach people enough syntax and properties for them to be able to go into the applescript library, pull up a dictionary, and script any application they want too.

Nigel,
I can see why you want me to go into what exactly applescript is and how exactly it works, but I am targeting an audience of people who want to jump right into the code and start learning how to manipulate applications. I do appreciate what you are saying about the applescript terminology, and I admit that I am at fault for using the terminology of other codes. I will most definitely make sure to–in the third tutorial (I’ve already made the second)–talk about how I’ve been using the wrong syntax. Lastly, I completely forgot about how people may have changed their alert noise and so beep would make a different sound on their machine. I will make sure to make a mention of that as well in the next tutorial. Thank you for the advice!

SuperMacGuy,
As I said above to Bazzie Wazzie, my whole curriculum is going to be based around the applescript dictionaries. I’m going to get people into the habit of looking to the dictionaries for functions rather than guessing or thinking that a single function will work in any application. I will definitely mention, as you said, that by no means can you carry a function from one application to another.

Thank you all for the advice and suggestions. I will definitely be using what you guys have told me in the next tutorial. Thanks!

~Josh Fletcher

You’re maybe right about the long and boring stuff.

one more thing: Maybe you should think about lowering you screen resolution while recording. The movie loads by default in 480P and not in 720P on YouTube. So initially your movie is a little bit blurry. Did you do the screen recording with QuickTime? There is other software around who can capture windows and screen area’s.

Well keep up the good work fletch!

Off topic, but I use ScreenFlow and that is pretty nice and easy to do simple edits, zoom in on a window, highlight mouse pointer etc. I think it also comes with a free FlipForMac encoder sometimes too (not that I want to promote WMV, but you can convert WMV to QT/mp4 etc easily with it).