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!
Share
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
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
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 Permalink rate up rate down Reply@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.
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 Permalink rate up rate down ReplyAppleScript! Looking forward to more! Any how-to book recommendations?
December 27 2007 at 9:13 PM Report abuse Permalink rate up rate down ReplyI 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 Permalink rate up rate down ReplyQuestion, 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.
Add me to the chorus of "more"s
December 27 2007 at 5:58 PM Report abuse Permalink rate up rate down ReplyI 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 Permalink rate up rate down ReplyOne 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 Permalink rate up rate down ReplyHot Apps on TUAW
Deals of the Day
more deals- Refurb Apple MacBook Air Laptops: 12" 64GB SSD for $699 + free shipping
- JVC Motion Sensing Clock Radio with Dual iPod Docks for $55 + free shipping
- Apple iPhone Headset with Mic for $4 + $2 s&h
- miFrame Picture Frame Dock for iPad for $64 + $8 s&h
- Refurb Apple iPod nano 8GB MP3 Player for $99 + free shipping, 16GB for $119
- Hannspree Apple-Shaped 28" 1080p LCD HDTV for $270 + free shipping
Software Updates
more updates- EFI Firmware Update brings Lion Internet Recovery to 2010-model Macs
- OS X Lion 10.7.3 released with Safari 5.1.3, Wi-Fi bug fix
- Aperture updated to 3.2.2, addresses Photo Stream issue
- Apple updates Keynote to address Lion issues
- Google Search app gets new look on iPad
- Apple releases Apple TV Software Update 4.4.3



12 Comments