Learning AppleScript resources?

I’m wanting to learn AppleScript, and am looking for suggestions on the best resources (books, websites, videos, etc.)? I started with the website AppleScript: The language of Automation which is built around the book AppleScript 1-2-3, which is no longer in print, and I don’t think that I want the Kindle version. Also suggested was AppleScript: The Definitive Guide: Scripting and Automating Your Mac, but the reviews that I read stated that it’s not ideal for a beginner, of which I am.

I’m wanting to learn AppleScript so that I can interact and write scripts to work with the Finder, Mail, and possibly other Mac apps, so it’s imperative that stuff is covered in the resource.

Any other great suggestions for going about learning AppleScript?

I generally get the feeling that Apple no longer promotes AS as an end-user scripting tool. They tried (and many would say failed) with Automator, and now they have added the previously iOS-exclusive Shortcuts to macOS Monterey. So if you lack a strong background in programming, I would start with Shortcuts and see if that gets you what you need.

However, AS is still fully supported, and there are some great current resources out there, such as the MacScripter forum, and Late Night Software’s venerable Script Debugger (“lite” version is free) along with their blogs and forums. In terms of books, there doesn’t seem to be any written in the last 10 years, but Matt Neuburg’s “Definitive Guide” (which you mentioned) is still the gold standard.

3 Likes

Jeff, thanks for the response. The first AS that I’d love to write is one that nightly goes through my email, and deletes (or at least moves to the Trash) several different email periodicals that I receive. I don’t think that something like that can be done with a Shortcut, but I could be wrong.

I started programming way back in 1976 with BASIC, and then moved into several other languages. However, I haven’t had a need to write any code in long time (at least a decade, and that was with Ruby). It’s been suggested that I learn Javascript, but that may be overkill for what I’m wanting and occasionally needing to do, so I thought I’d play with AS.

Do you feel that “Definitive Guide” is a good beginner book? I did the first chapter of AppleScript 1-2-3 online, and found it pretty good, and easy to comprehend.

Cheers!

Sounds like you have some background in programming, so you probably would get on well with “Definitive Guide.” Matt is one of my favorite tech writers, but a “beginner book”? That’s really hard to say.

Your specific use case sounds like something a Rule in Mail would handle (Mail > Preferences > Rules). Have you looked into that? I guess my advice would be, if you want to acquire a new skill for its own sake, and you’ve selected “learning AppleScript” as that skill, then absolutely dive in to the resources I mentioned. On the other hand, if you’re trying to solve a specific problem (or two), then I’d Google for existing solutions, rather than trying to roll my own. Hope that helps!

My experience with AppleScript says there can be no book for it, since the syntax for the language is different for every app you script!

Seriously, it’s exasperating. The phrasing changes depending on the AS dictionary for each app, so once you learn how to script one app, you have to learn it all again for another app.

The basic AppleScript language is learnable (and not bad), but you’re stuck with trial and error or searching for examples on the internet for the specific app you’re trying to script. I’ve never found any books on the topic to be much help (Tao of AppleScript comes to mind and I’m sure I have a half dozen others). They all mean well, but were useless unless you were trying to do exactly the examples they suggested.

Wouldn’t Apple Mail’s Rules work better for that?

2 Likes

Or more precisely, the language itself is very simple and basic. But its power is not in the language, but in the commands your scripts can send to applications. And each application defines its own set of commands that it will respond to.

And, like everything else, some software will include good documentation, but most will not.

You can view an app’s dictionary (the commands it supports) using the Script Editor app:

  • Launch Script Editor
  • File → Open Dictionary…
  • Choose the app

But the quality of the documentation you find in the app will depend entirely on how well the developer wrote it. And what you find will be the data types and arguments to the messages. There won’t be anything telling you which messages to send in order to do what you want done.

Although far from a tutorial, if you are familiar with general programming concepts, the AppleScript Language Guide, may be useful.

And you’ll want to keep this document bookmarked as a reference manual after you become familiar with the language.

Rules in Mail are extremely limited, unfortunately. I do have a single need at the moment, but I’m hoping that learning AS (or another scripting language), I’ll find myriad things to do it that haven’t come to mind as of yet.

Here’s a review that I found for Matt’s book:

This book is certainly the definitive text for really learning how to write AppleScripts. It is not easy, and it does not have a gentle intro that leads you into the language. The text assumes (perhaps more implicitly) that the reader knows something about a variety of other programming languages (PERL, Lisp come to mind). I will seek a more gentle into as I am starting at ground zero with AppleScript, but this will be my “go to” reference for subtle variations of the language. If you really want to leran AppleScript well and be able to write sophisticated code, this text is a must for your bookshelf.

Another review states:

The most important thing you need to know before buying this book is some AppleScript. If you are looking for a book to teach you AS from the ground up, this is not it. What you most likely need for that is Apple Training Series: AppleScript 1-2-3 .

However, if you’ve already used Soghoian and Cheeseman, or Learn AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X (Learn (Apress)) , then this most definitely is the book for you.

This is the book that will make the difference between you as a scripter who knows their way around but keeps getting stuck and looking things up on the internet and you as a scripter who can figure out stuff for themselves and help others who get stuck.

I’d been AppleScripting for months under the illusion that I knew my way around (even though I kept getting stymied trying to do anything new). The feeling you get when you actually write a script straight out of your head to solve a novel problem AND it compiles first time…ooohh!!! Scripter joy!! This book will help you get there, but like I said, if you’re a beginner: look elsewhere first. This will only put you off.

I’m definitely in the beginning stages with AS though I’ve coded in other languages over the years, and am torn between which of the aforementioned books to go with.

Apple Mail’s rules are adept at finding the emails in question, but there’s no way to automate it so that it runs at a scheduled time. I’d have to run the rule manually everyday, which is something that I’d prefer not to do.

And I did wonder about the phrasing of each app, and the various dictionaries. I can see how this can be very annoying, tiring and exasperating. Thanks for the feedback.

Yes, but you could create a rule in Mail and then use an AppleScript (or Automator action) to run the rule on a schedule.

This might be easier than making the script do everything.

1 Like

@Shamino, thanks for the info! This is very useful! I just opened Mail’s dictionary, and there’s a ton in there. Though one has to learn the dictionary for each app, it does make the potential that much appealing.

Fair and valid point! :slight_smile:

The AppleScript-Users mailing list (AppleScript-Users Info Page) has become very quiet of late but has some very helpful subscribers who have rapidly solved problems for me. A recent email asking for beginners’ guidance produced this response from Ed Stockly, which has some very helpful pointers.

Welcome to the party!

AppleScript
macosautomation.com
http://macosautomation.com/
This web page is probably the best introduction. It’s run by Sal Soghoian, former product manager for automation at Apple. You’ll find links to AppleScript tutorial on the first page.

MacScripter
https://macscripter.net/

This is a web forum dedicated to AppleScript (mostly) where once you register you can search years of posts and responses, many with good example scripts.

Scripting Safari for Basic Control with AppleScript and Javascript - AppleScript - Late Night Software Ltd.
https://forum.latenightsw.com/

This is a forum for the Script Editing and development package available (Script Debugger). While there are many topics and thread devoted to using that software, there are also several AppleScript topics and general automation topics. I find that questions get answered quicker here than anywhere else.

2 Likes

I actually love AppleScript as a scripting tool (not to be confused with a programming language). But if I was starting out, I would use JavaScript for automation instead. I thought about learning it myself, but I already know AppleScript so why bother?

I would love to see apple bring a subset of swift as a scripting tool. That I did learn, it’s great. Alas I have heard of no plans from apple to do so

I did convert some scripts to shortcuts, it is a good implementation. If you do go that route, my advice is to use shortcuts for as much as possible, then write JavaScript or AppleScript to do what you cannot do with shortcuts

Finally, the one thing I keep forgetting, if you use a handler (subroutine) while inside a tell block, don’t forget the my keyword. Funny, I know that and still forget

1 Like

Your first task is easily performed within Mail itself as a Rule. You add criteria to screen the senders, titles what not and then have the run automatically delete the effected emails. I would recommend creating a separate mail box for this purpose, so you can review them first before you inadvertently delete your trash.

Another way is to use Smart Mailboxes, they are just views that collect mail that meets your criteria, then you can bulk delete easily. Scripting would be a waste of time, IMHO

perhaps not promoted by Apple; but David Sparks interviewed Apple’s Vivek Bhardwaj in Mac Power Users #592: WWDC 2021 and the Future of Mac Automation - Relay FM who affirmed Apple’s commitment to AppleScript.

Our own app includes a little script editor where users can use languages like AppleScript or JavaScript to connect info.

Agreed. I chose the word “promoted” deliberately.

If only HyperCard were still maintained. :slight_smile:

2 Likes

I fondly remember it. I wrote some code for my honour’s thesis in psychology in it, not yesterday.

to qualify my bit about the interview, I found it very informative. Apple explained their commitment, and it stands to reason. Not that I expect AppleScript to get a lot of attention. But we do not find AppleScript needs a lot of attention. We just want Apple to make sure they do not break it. And we’d like to see more of their apps have some automation, whatever the language, including an API for linking, per this chapter: A Manifesto for User and Automation Interfaces for Hyperlinking, which we’re adapting into a website (stay tuned … :wink: ).

2 Likes

If you want to really understand AppleScript as a language while you’re learning to use it, find a used copy of AppleScript 1-2-3, read it cover to cover and type every word of AppleScript code right along with the authors, and then read Matt Neuburg’s book so he can break the language down and tell you everything that’s wrong with it. That book taught me more about writing computer code, of any kind, than any other book I’ve ever read.

If instead you’d just like to find AppleScripts that do what you need to accomplish, just keep mining all of the online resources, because somebody somewhere has already tried to do what you’re trying to do, and they’ve likely posted the code they ended up using. When you start adapting that code for your purposes, you’ll likely learn what you need to know.

I’ve discovered over the years that I’m not a good learner when doing the latter method, but I get the impression that most people actually do prefer that method.

My preference is for reading a book by a really talented, thoughtful writer-teacher who can help me understand the full scope of what I’m trying to grasp. I include Danny Goodman and his HyperCard books in that camp, along with Matt Neuburg for AppleScript and Mark Lutz for Python.

A few years ago I thought it would make more sense to learn Javascript for Automation than keep using AppleScript, but I soon discovered that there was no Goodman/Neuburg/Lutz-level teacher to learn that from, so that was a dead end for me.

Recently I discovered Learn AppleScript, which you mentioned above, and I felt that did a better than average job of teaching, especially for a book written in an era when new tech books of that scope tend to be poorly conceived and edited because they get released so quickly to avoid becoming obsolete before they hit the shelves. I’d say that might be worth your while, especially if you only want to read one book.

2 Likes