Anyone can Applescript

Great resources for learning Applescript.

Applescript is a great resource provided free by Apple for their users and it comes with every Mac. It is by far the easiest scripting language to learn, since it uses mostly English-like words in its code. Apple also provides a basice, but good, scripting editor (called Script Editor) and you can find this in your Applications folder. You will want to drag the Script Editor icon to your Mac’s dock for easy access.

Why do I love Applescript? For one, it makes my job way easier. For example, a common problem with Entourage and Internet browsers is that fonts will often appear garbled. One fix to that is here.

Done reading? Wouldn’t it be great to just click one button and have your computer locate those caches and delete them, rather than looking for them yourself (which of the libraries contains these cache files again?), then dragging them to the trash, then emptying the trash, the following script will do all that. Just copy and paste the following code into your Script Editor. Then tweak it. Change “Macintosh HD” to the name of your computer–which you can find under the disk icon on your desktop. Change “youruseraccount” to…well…your user account. Then save. Next time you see garbled text in Entourage, run the script. (Note: if you don’t have these two files in your User’s Library’s Cache folder, the script will give you an error. But then you won’t have the garbled text problem, either…so it’s a win…kinda.)

(* Open this script in Script Editor. CHANGE the text inbetween Users: and Library to the name of your user account. If you don't do this, you will get an error!!! Click on the Compile hammer, then click run. You can save it as an applet, and place it in your Dock. *)

tell application "Finder"

set MSCache to alias "Macintosh"
set TBCache to alias "Macintosh HD:Users:youruseraccount:Library:Caches:Tasman Browser.cache"

delete MSCache
delete TBCache

end tell

Okay, I’m putting the cart before the horse. You might be a little apprehensive about having to learn some geeky computer programming (er, scripting). I was like you. But slowly (very slowly) I learned and practiced, and now I’m just good enough to use Applescript on a daily basis.

To tell you a story: Once upon a time, I was a high school student who excelled in every subject except math. In fact, I hated math, or it hated me. In fact, I flunked pre-algebra in middle school, and barely passed the retake.

Several years ago, I tried to take a C++ programming course. It proved impossible. I finally quit when the instructor ordered us to write a program that would suss out the Fibonnaci sequence.

But only two months ago, I used Applescript to write a script that did just that. Although it took a lot for me to get my brain around the Fibonacci sequence in the first place, I think Applescripting helped me do something mathematically that was impossible for me just a short while ago.

set fibList to {0, 1}
repeat while (count of fibList) is less than 20
set a to item -2 of fibList
set b to item -1 of fibList
set c to a + b
copy c to end of fibList
end repeat

Which is to say, If I can do it, ANYONE can Applescript.

Here are some great resources to get you started.

Ben Waldie’s Applescript video tutorial for the Virtual Training Company’s Online and CD Computer Software Training. This is a great place to start learning Applescript. Waldie covers the fundamentals, and because the videos are done in modules, you can learn at your own pace. The course costs $99.95, but you could just get a subscription for $30/month, which enables you to take all the courses they offer.

TecSoft’s “Workflow Automation with Applescript” software. The course has been updated and covers scripting InDesign, FileMaker Pro, and the OS X. It’s a bargain at $49.95.

A quick introduction to Applescript can be found at MacWorld’s website. For a longer introduction, see Apple’s Developer Connection…(yes, as soon as you start writing scripts, you are considered a developer. Cool.)

Finally, the world of Applescript from soup to nuts can be found at This is the site for tutorials, resources, sample scripts, and more. Best of all, you can joing the Macscripter community and search their database for answers to almost every question.

There is one caveat: no one on these forums is going to write a script for you. You will often see people pretending to be “noobies” with posts stating that they need a script that will do such and such. Very rarely do they get replies. Generally, you should try solving your scripting problems yourself, and then post your scripts so that others can see your hard work. Given that you really are a noobie, the experts will be more than willing to give you sage advice on how to fix or improve your scripts.

In my next post, I’m going to turn my attention away from Applescript for the moment and talk about one of my favorite tips for using InDesign. In this blog, I’m hoping to cover the wide spectrum of Mac Production Artistry, and scripting is only one facet of it.

See you soon.


About this entry