To recap the end of Part One, your goal will be to build a script that will save your emails as text files. The actual programming will be covered in Part Three and, when we get there, I’ll try to stay more “conceptual”.
My goal will be to give you a feel for how an AppleScript does its job — but still include enough real-life code to keep it interesting for more experienced scripters (or for people who came here from a search engine looking for a bit of code to get their scripts up and running!)
But, if you are a beginner, don’t let those computer code snippets intimidate you! They are included primarily so that you can see what a real-life Script looks like and not with any expectation that you master the intricacies of the AppleScript language.
After all, this is really an exercise in teaching you the fundamentals of thinking and speaking AppleScript. In other words, this is going to be more like an English class in literature where we talk about books and what they mean — and not a grammar lesson.
In fact, that metaphor is actually a pretty good way to get started!
The First Step Is Between Your Ears
As I mentioned in Part One, AppleScript is an “English-like” programming language.
What we are going to do in this lesson is to state our goals as clearly as we can — and do so in plain, everyday language. Once we’ve done that, we’ll set about writing an AppleScript that matches up with that description.
First, we say it in English…. then we say it in “English-like”.
Writing a good AppleScript is like…. (wait for it) …. writing a good anything!
Most things that are well-written have probably started from a place of being well-thought-out, right? That’s not to say that you won’t discover some fun, unexpected stuff along the way — but actions begin with intentions. My experience is this: The clearer you are about your intentions when you start, the more you’ll make the right choices along the way.1
And the more likely you’ll end up with a working thing at the end of your journey.
The Goal of the Script (In Plain English)
First, we need to state our overall goal as clearly as we can. For this first sample script, that goal is:
“I want a script that will save emails as text files.”
The Basic Elements We’ll Need In the Script:
Now that we know what we want to do, we’ll flesh out the details more fully:
- I use the Apple Mail application to read my emails.
- I want to be able to save emails as text files.
- I want to be able to save more than one email at a time.
- I want to be able to control where the text files are saved to.
- I want the new text files to have distinctive names so that I can tell them apart more easily.
- I want the script to come up with those names so that I don’t have to do it for each file.
- I’d like to welcome everyone to the Veritrope.com “Den of Zen”… [↩]