Skip to Content

AppleScript: the Script Editor

Before you can build your first AppleScript you need to know some basics: what a script-able application is and how to use the Script Editor.

Script-able Applications
Basically, script-able applications are applications in which the developer has included a set of "instructions" that the Script Editor understands and can use. Some apps are not script-able but most Apple apps are and, of course, Mac OS X itself is script-able.

The Script Editor
The Script Editor is a very simple application, but it allows you to do some very powerful things. The Script Editor is located in your Applications folder (Applications : AppleScript : Script Editor.app) by default. The editor has a simple interface with a prominent text entry area. It also has 5 buttons in the toolbar; for now we will only focus on the "Run" and "Stop" buttons. The run button will run the currently typed script, and the stop button will cancel a running script.


Running a Script
Let's delve right into the Script Editor by running your first AppleScript! We will use the "tell" command. This command will allow you to tell a specific application to do something. For instance, if I wanted to open iTunes, I would type:

tell application "iTunes" to activate

You can substitute "iTunes" with any other application on your Mac, however, you must retain capitalization and spacing (if any) and include the quote marks around the application name. Now try typing the script and clicking the "Run" button at the top of the window. iTunes will open. Substitute activate with quit and run the script again. iTunes will now quit.

As you can see, AppleScript commands are very "English-like" in their structure. This is one reason that AppleScript is very easy to pick up as you go along.

Congratulations, you've just made your very first AppleScript!

Categories

Features How-tos

Before you can build your first AppleScript you need to know some basics: what a script-able application is and how to use the Script...
 

Add a Comment

*0 / 3000 Character Maximum

12 Comments

Filter by:
Mark Scrimshire

I am not an Applescript expert but I was able to create an Address Book plug-in that will let you Right-Click/Option-Click on a contact's email address and lookup the person on Spock.com, the people search engine. It is crude but seems to work quite well.

The script is available to anyone that wants it at http://www.ekive.com/spock/getscript.html

December 30 2007 at 3:20 PM Report abuse rate up rate down Reply
Bakari

Someone ask about suggest books on AppleScripting. I've just started with a 500+ page book by Stephen Kochan seems to cover the basics pretty well. I may never learn it totally, but it's fun just seeing how its done.

December 28 2007 at 3:58 PM Report abuse rate up rate down Reply
nicke

@warren

This is just a very simple script. In its current state it is not very useful. However this snippet might be very useful if you are trying to do something more extensive. Say that later down the line, you want to do this:
1: Activate iTunes.
2: Examine which tracks in your library lack rating.
3: Collect them to a new Playlist with the title "Unrated Tracks".
4: Start playing the first track in this playlist so you can start the rating of the tracks.
None of this is useful if you don't activate iTunes first. In addition, the script I just outlined might seem like a few mouse clicks away, but if you do this a couple of times a week it gets tedious. Double click an AS applet and all of it will be done in under a second. Maybe this particular script wouldn't of use for you, but try to think of a task you do a couple of times a week, or even maybe a couple of times a day. Do you see the beauty of automating it with an AppleScript?

@cory
I, too, thought that you would write more extensively and frequently on this topic. I hope you will in the future, for this is an interesting topic!

Cheers.

December 28 2007 at 5:13 AM Report abuse rate up rate down Reply
Bakari

Erica, you're just the techie to do an entire book on AS. Btw, i just saw your iPhone book in the bookstore today. Made me wish i had an iPhone. Can't wait til you get your iPod touch book published.

December 28 2007 at 3:58 AM Report abuse rate up rate down Reply
David Fischer

AppleScript! Looking forward to more! Any how-to book recommendations?

December 27 2007 at 9:13 PM Report abuse rate up rate down Reply
Jake

I personally love these articles, and prefer them to be at the length they are now, so it doesn't overwhelm me! Its great and looking forward to more articles!

December 27 2007 at 6:41 PM Report abuse rate up rate down Reply
warren

Question, why should I open itunes anyother way than just clicking on it? I really don't understand what this apple script is for.
Please don't laugh at me, I'm rather new to mac - but I'm loving it, and I want to know more.

December 27 2007 at 6:35 PM Report abuse rate up rate down Reply
Quine

Add me to the chorus of "more"s

December 27 2007 at 5:58 PM Report abuse rate up rate down Reply
Felix Pizarro

I am a newbie to Mac and sort of "too busy" and I find the "little snippets" articles great! Thanks!

December 27 2007 at 5:13 PM Report abuse rate up rate down Reply
Peter Payne

One note, AS is changed somewhat now that Leopard is here, with Automator's ability to record actions again. Some things can NOT be done easily with AS, like manipulating system preference pane options or assigning custom keyboard shortcuts, but Automator can record actions quite nicely.

December 27 2007 at 12:22 PM Report abuse rate up rate down Reply
Buy an ad here

Hot Apps on TUAW

Tweets

© 2012 AOL Inc. All Rights Reserved.